如何使用pdfkit通过相机拍摄的图像创建pdf [英] how to create a pdf from image which taken by camera with pdfkit
问题描述
您好我是 pdfkit
和iOS应用程序的新手,我想用设备拍照,然后将图像转换为pdf。使用相机拍照并将其保存在相机胶卷上工作完全正常,问题是当我想从该图像创建pdf时它需要图像的名称,我怎么能找到它?
和另一个问题是可以用 pdfkit
实现任何pdf编辑器来编辑图像吗?
感谢任何帮助。下面是我的 imagePickerController
代码。
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)
}
推荐答案
由于图像已经存储在 pickedImage $ c中,因此无需实例化新图像$ c>变量。您只需要使用
pickedImage
初始化新的 PDFPage
对象。使用 ImageKit
编辑图像,然后再使用它初始化新的 PDFPage
对象。
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)
}
这篇关于如何使用pdfkit通过相机拍摄的图像创建pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!