views:

364

answers:

1

Basically what I want to do is copy the already rendered content (a PDF drawn into the UIView's graphics context using CGContextDrawPDFPage()) onto a similar UIView, without having to re render the PDF. The idea is, that I'd then be able to perform an animated transform on the UIView and later re render the PDF with more accuracy. For both UIViews I'm using a larger-than-screen CATiledLayer to make it easier to rerender the PDF once the user zooms in, if that makes any difference.

Any tips? I'm kind of lost here.

+1  A: 

Assuming you have rendered a PDF page in a graphics context using code similar to the following

CGPDFDocumentRef document = CGPDFDocumentCreateWithURL (filename_url);
CGPDFPageRef page = CGPDFDocumentGetPage (document, pageNumber); 
CGContextDrawPDFPage (context, page); 
CGPDFDocumentRelease (document);

This code will save the contents of pdfView to a UIImage

UIGraphicsBeginImageContext(pdfView.bounds.size);
[pdfView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *pdfViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
adam
Still requires re rendering the PDF, unless I render it to an image all the time, which supposedly has considerable overhead.
Joonas Trussmann
Assuming you have already rendered the PDF in the current graphics context, using code similar to that I've added to the post above, using the lower code will not re render the PDF. Imagine it like taking a screenshot of your desktop.
adam
Alas, I tried that before and it does in fact re render the PDF. Could be due to the fact that I'm using a CATiledLayer?
Joonas Trussmann
Is using CATiledLayer imperative?
adam
It does greatly simplify zooming said PDFs (re rendering them when zoomed). While I did come up with an alternative solution to this issue, it'd still be nice to know if it's possible to essentially copy the rendered contents of a context from one UIView to that of an identical UIView.I understand that graphics contexts are by design device/media specific and not meant to be interoperable, but I'm sure I'm not the only one that's had a similar issue.
Joonas Trussmann