Reputation:
Not sure if this is a bug as PDFKit is in Beta on iOS, but when I create a PDFDocument based on an array of images (using PDFPage(image:), it flips the image vertically.
@IBAction func export(_ sender: Any){
let apdf = PDFDocument()
var i = 0
while i < arrayOfImages.count{
let image = arrayOfImages[i]
let pdfpage = PDFPage(image: image)
apdf.insert(pdfpage!, at: i)
i = i + 1
}
//Code for sharing the PDF Document
let objectsToShare = [apdf.dataRepresentation()]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = view
self.present(activityVC, animated: true, completion: nil)
}
The output is this:
I am 100% sure that the source images are not flipped because they are used elsewhere in the app. You can set the rotation of a PDFPage but I can't see any way to manually flip it back.
Upvotes: 3
Views: 1201
Reputation:
One (bad) solution to this bug (?) is to flip the image vertically in advance so it gets flipped back:
let img = arrayOfImages[i]
let image = UIImage(cgImage: img.cgImage!, scale: img.scale, orientation: .downMirrored)
let pdfpage = PDFPage(image: image)
Upvotes: 1