I am trying to create a PDF using PDFKit in swift4.0.
The PDF itself was easy to create, but when I opened the contents, it turned upside down.
Some specification may be insufficient/extra.Please let me know.
import UIKit
import PDFKit
classViewController:UIViewController {
override func viewDidLoad(){
super.viewDidLoad()
}
override funcdidReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
}
// PDF and return URL
func createPDF()->URL{
let document —PDFDocument=PDFDocument()
Let page1:PDFPage=PDFPage(image:UIImage(named:"IMG_0115.jpg")!)!
document.insert (page1, at: document.pageCount)
let documentsPath=NSSearchPathForDirectoriesInDomains (FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!
let url:URL=URL(fileURLWithPath:documentsPath+"/output.pdf")
document.write(to:url)
return url
}
@ IBAction funcpdfAction(_sender:Any){
let url —URL = createPDF()
let items = [url]
let activityVc = UIAactivityViewController (activityItems, applicationActivities:nil)
self.present(activityVc, animated:true, completion:nil)
}
}
I think it's a PDFKit bug.
Currently, the only workaround is to reverse the UIImage and then generate a PDFPage.
© 2024 OneMinuteCode. All rights reserved.