title: Java PDFBox Multi-Page Document With Headings and Table of Contents
body: <p>The PDFBox v2.0 is still growing and doesn't have any nice and easy examples to get started with. </p>
  
  <p>I need to create a multi-page PDF dynamically from an object; with TableOfContents and Headings!</p>
  
  <p>How do I create Numbered Headings? (Increasing the font size is not an option because the TableOfContents has to know their location[page number] in the document)</p>
  
  <p>Example: </p>
  
  <pre><code>                       Table of Contents    
  Document Title Here
        1- Intro......................................................1
        2- Heading....................................................2
             2.1- SubHeading1 ........................................2
             2.2- SubHeading2 ........................................5
  
                                Page 1           
  </code></pre>
  
  <p><br /></p>
  
  <pre><code>                       Document Title Here
       1- Intro
             This is an intro to the document....
  
       2- Heading
       2.1- Subheading
        Some text here...
       ........
  
  
                             Page 2
  </code></pre>
  
  <p>I have two problems:</p>
  
  <ol>
  <li><p>I followed this example here: <a href="https://stackoverflow.com/questions/23553094/pdfbox-how-to-create-table-of-contents">PDFBox - how to create table of contents</a> but it didn't create any TableOfContents. 
  I'm getting this exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Destination of a GoTo action must be a page dictionary object
  at org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo.setDestination(PDActionGoTo.java:90)
  </code></pre>
  
  <p>I removed the PDActionGoTo as the answer comment said; it didn't give any exception but it didn't create any TableOfContents</p></li>
  <li><p>I have no idea how to make headings!</p></li>
  </ol>