Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show PDF in iPad using CGPDF APIs [closed]

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

like image 911
AJ. Avatar asked Jun 15 '10 05:06

AJ.


People also ask

How do I manage PDF on iPad?

Here's how to edit a PDF on an iPad.Start by tapping the “Select a file” button. You'll be prompted to navigate to the file's location, whether on your device or on a cloud-based service. Click on the file you want to upload and sign in. You'll get an array of tools you can use to edit your PDF.

What is the default PDF viewer on iPad?

It's no different on an iPhone or iPad. The default method to read PDF files on these devices is using iBooks, which was included as a preloaded app beginning with iOS 8. Sure, you can view PDFs in Safari, but you won't have very many additional options.


2 Answers

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!

like image 50
Sasho Avatar answered Oct 11 '22 23:10

Sasho


Displaying the PDF with the Quartz APIs is pretty easy. But there's no native support for link annotations. Basically, you need to parse the "Annots" dictionary inside the pdf, and then find the correct page (which can be GoTo references, or named references, or ~10 other types; see the Adobe PDF Reference 1.7 document, the section about Actions), and the calculate the coordinates to the displayed page.

I've written a [commercial] library that includes parsing link annotations, and many more features. You may wanna check out http://pspdfkit.com

like image 38
steipete Avatar answered Oct 11 '22 23:10

steipete