Reputation: 1450
I use code from huckingwithswift.com as it is:
private func imageFromPDF(page: CGPDFPage) -> UIImage {
let pageRect = page.getBoxRect(.mediaBox)
let renderer = UIGraphicsImageRenderer(size: pageRect.size)
let image = renderer.image { ctx in
UIColor.white.set()
ctx.fill(pageRect)
ctx.cgContext.translateBy(x: 0.0, y: pageRect.size.height)
ctx.cgContext.scaleBy(x: 1.0, y: -1.0)
ctx.cgContext.drawPDFPage(page)
}
return image
}
, and on previous examples (QRCode in PDF) it works good. Now a test ingeneer reported that my application can not see QRCodes on such page:
UIGraphicsImageRenderer creates an image, which looks like You can see, it does not see this QRCodes It may be because of different layers, but how to make all content be visible?
Upvotes: 1
Views: 76
Reputation: 83
Annotations are drawn only in thumbnails. Try PDFPage class. You need render big thumb, not page.
#import <PDFKit/PDFKit.h>
+ (UIImage *)image:(PDFPage *)page
{
CGRect pageRect = [ page boundsForBox:kPDFDisplayBoxMediaBox ];
pageRect = CGRectApplyAffineTransform(pageRect, [ page transformForBox:kPDFDisplayBoxMediaBox ]);
UIImage * image = [ page thumbnailOfSize:pageRect.size forBox:kPDFDisplayBoxMediaBox ];
return image;
}
Upvotes: 1