How To Get table of content in Vfr Reader for Pdf in iphone sdk?

274 views Asked by At

I am using VFR reader to display my pdf's. I need to extract the Table of Contents on a button click and display it in a tableview then it should lead to the respective pages while tapping on each.

1

There are 1 answers

0
steipete On

Parsing the PDF Table of Contents is actually not extremely hard. You can use a tool like Apple's PDF "Voyeur" to see the structure or something like Adobe Acrobat's Preflight Browser:

enter image description here

You see that the "Outline" is a fairly simple tree that can be parsed using the various CGPDF* functions. The challenge here is to also parse the destination/action type. PDF doesn't make things too easy and doesn't give you a page number, instead usually you will find a linked named destination. This can be resolved by cross-referencing another table, it's best to look this up in the PDF spec. This is of course just one of the options, it can also be that the destination is one of the > 10 action types that rage from GoTo over named actions (e.g. Next Page) to JavaScript (e.g. this.pageNum = x). In the image above you see a classical GoTo action with the longer string being the named reference.

There are also some other special cases, notably for older latex documents and some pages from the PDF 1.1 spec that did things a bit differently, so be careful about implementing all corner-cases of the PDF spec to not get surprises later on.

Outlines sometimes also include URI actions, so at least implement that type as well. And they can also have font styles and color, so you won't ever get bored. Been there, done that in our commercial PSPDFKit PDF SDK for iOS and Android.