0

I have PDF pages that are saved as spreads. This works out for me in one view where the user can zoom, highlight text and click on hyperlinks. However, I want to use the same PDF files in another view that requires individual pages instead of spreads. I'm hoping I can avoid having to have the user download extraneous PDF files.

I was able to adapt the awesome "Leaves" project to do what I wanted. But can I change any of the following code to get it to draw a PDF but cropping off either the right or left half of the page, and changing the offset when necessary?

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


- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
    {
        CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
        CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
        CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
        CGContextScaleCTM(ctx, 1.0, -1.0);
        CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, 0, true));
        CGContextDrawPDFPage(ctx, myPageRef);
    } 

Or if there's another approach to accomplishing the same thing, that would also be welcome.

Thanks!

user2844331
  • 109
  • 6
  • I don't remember the specifics of the bounds used to render a pdf but you should have a CGContext at some point that you can then crop. – 0xFADE Jan 02 '14 at 19:57
  • Is that part of the drawLayer:inContext method above? I can't figure out what these parameters are referring to, only that they work in drawing a single full page PDF. If I try switching in the spread PDFs, they shrink down to fit the whole spread in the frame. What I want it to do is crop off either half of the spread. Is there a guide somewhere to using CGContextDrawPDFPage? – user2844331 Jan 03 '14 at 15:07

0 Answers0