Show PDF in iPad using CGPDF APIs

AJ. picture AJ. · Jun 15, 2010 · Viewed 15.4k times · Source

I have learned Apple has release CGPDF APIs in SDK 3.2 for drawing PDF context.

What I understand from these APIs is that you can draw a PDF to a data object or a PDF file. You can then export it, may be, to your sandbox's directory OR add as an attachment in the mail.

But I am not sure if we can use these APIs to read a PDF from application bundle and show it to the user page-by-page on the screen. What I want to do is open a PDF of a magazine in a magazine reader app.

I was also wondering if we can identify the links in a PDF file and open them in the app.

Let me know if have done OR doing anything like this.

Thanks AJ

Answer

Sasho picture Sasho · Jun 16, 2010

In API documentation there is a way to load a PDF (with Quartz): CGPDFDocument is the object you need and CGPDFDocumentCreateWithURL is probably the constructor you are looking for.

Here are some examples on how to do it: http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-TPXREF109

I have spent a lot of time on this - and it seems you need to use CATiledLayers to zoom those PDFs properly!

There are some good examples on the net on how to do that...

I will put a link/solution here as soon as I have something ready!