Contex Drawing + Pagination Contex Drawing + Pagination ios ios

Contex Drawing + Pagination


I don't think you need the code which flips the PDF upside down. I've done this before (manual pagination, but without a scroll view) and never had to flip the context vertically. My main concern is that you are doing it on every iteration - if you have a valid reason for flipping it, you probably don't need it in the loop, but just once before the loop begins. Also the code CGContextTranslateCTM(pdfContext,0,-ty); might need to be replaced with CGContextTranslateCTM(pdfContext,0,heightOfPdf);

If that doesn't work, try UIGraphicsBeginPDFPage(); instead of CGContextBeginPage(), that's the only major difference between your code and mine.


This github project can definitely help you.

- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index + 1);CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFMediaBox),                                        CGContextGetClipBoundingBox(ctx));CGContextConcatCTM(ctx, transform);CGContextDrawPDFPage(ctx, page);

}


Found this link to render a PDF, it says about multiple pages but haven't shown an implementation. It doesnt straight away answer to your question but it tells a simpler method to render a pdf with much less translation and transforms.

Render PDF

Generate Multipage PDF-anoop