how to create a pdf from image which taken by camera with pdfkit

倾然丶 夕夏残阳落幕 提交于 2019-12-04 06:25:14

问题


Hi I am new to pdfkit and iOS applications, I want to take a picture with device and then convert the image to pdf. taking pictures with camera and saving it on Camera Roll works completely fine, the problem is when I want to create pdf from that image it needs the name of the image, how I can find it? and another question is it possible to implement any pdf editor with pdfkit to edit image? Appreciate any help. below is my imagePickerController codes.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

    if (Mylibrary)
    {

    }
    else
    {
        UIImageWriteToSavedPhotosAlbum(pickedImage!, nil, nil, nil);
        let image = UIImage(named: "????") //the problem is here
        let newPage = PDFPage(image: image!)
    }

    picker.dismiss(animated: true, completion: nil)




}

回答1:


There's no need to instantiate a new image since the image is already stored in the pickedImage variable. You just need to initialize the new PDFPage object with pickedImage. Use ImageKit to edit the image before using it to initialize a new PDFPage object.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    guard let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else { return }

    // Adds pickedImage to the user’s Camera Roll album.
    UIImageWriteToSavedPhotosAlbum(pickedImage, nil, nil, nil)
    // Creates a new PDFPage object and initializes it with pickedImage.
    let newPage = PDFPage(image: pickedImage)

    dismiss(animated: true, completion: nil)
}


来源:https://stackoverflow.com/questions/48609287/how-to-create-a-pdf-from-image-which-taken-by-camera-with-pdfkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!