title: How to obtain PDF table of contents (outline) data in iOS (iPad)?
body: <p>I am building an iPad application that displays PDFs, and I'd like to be able to display the table of contents and the let user navigate to the relevant pages.</p>
  
  <p>I have invested several hours in research at this point, and it appears that since PDFKit is [not supported in iOS], my only option is to parse the PDF meta data manually. </p>
  
  <p>I have looked at several solutions, but all of them are silent on one point - how to associate a page in the "outline" metadata with the real page number of the item. I have examined my PDF document with [the Voyeur tool] and I can see the outline in the tree.</p>
  
  <p>[This solution] helped me figure out how to navigate down the Outline/A/S/D tree to find the "Dest" object, but it performs some kind of object comparison using [self.pages indexOfObjectIdenticalTo:destPageDic] that I don't understand.</p>
  
  <p>I have read the [official PDF spec from adobe], and section "12.3.2.3 Named Destinations" describes the way that an outline entry can point to a page:</p>
  
  <blockquote>
    <p>Instead of being defined directly with
    the explicit syntax shown in Table
    151, a destination may be referred to
    indirectly by means of a name object
    (PDF 1.1) or a byte string (PDF 1.2).</p>
  </blockquote>
  
  <p>And continues with this line which is utterly incomprehensible to me:</p>
  
  <blockquote>
    <p>The value of this entry shall be a
    dictionary in which each key is a
    destination name and the corresponding
    value is either an array defining the
    destination, using the syntax shown in
    Table 151, or a dictionary with a D
    entry whose value is such an array.</p>
  </blockquote>
  
  <p>This refers to page 366, "12.3.2.2 Explicit Destinations" where a table describes a page: "In each case, page is an indirect reference to a page object"</p>
  
  <p>So is the result of CGPDFDocumentGetPage or CGPDFPageGetDictionary an "indirect reference to a page object"?</p>
  
  <p>I found a [thread on lists.apple.com] that discusses. [This comment] implies that you can compare the address (in memory?) of a CGPDFPageGetDictionary object for a given page and compare it to the pages in the "Outline" tree of the PDF meta data.</p>
  
  <p>However, when I look at the address of page objects in the Outline tree and compare them to addresses they are never the same. The line used in that thread "TTDPRINT(@"%d => %p", k+1, dict);" is printing "dict" as a pointer in memory.. there's no reason to believe that an object returned there would be the same as one returned somewhere else.. they'd be in different places in memory!</p>
  
  <p>My last hope was to look at the source code from apple's command line "outline" tool [mentioned in this book] (as [suggested by this thread]), but I can't find it anywhere. </p>
  
  <p>Bottom line - does anyone have some insight into how PDF outlines work, or know of some open source code (preferably objective-c) that reads PDF outlines?</p>
  
  <p><strong>ARGG: I had all kinds of links posted here, but apparently a new user can only post one link at a time</strong></p>