title: How to create bookmarks in a PDF when exporting a form from HTML
body: <p>I have a small html form that exports to a PDF. The PDF will be very long and I need to be able to create bookmarks within the HTML so that each bookmark can link to the section. For example, I would like to have a bookmark in the PDF labeled section 6 that will link to section 6 when the user clicks on it within the PDF. I've tried various different ways to achieve this including importing XML.</p>
  
  <p>Here is my js fiddle. I hope i made sense!</p>
  
  <p><a href="https://jsfiddle.net/3g59L4cv/2/" rel="nofollow noreferrer">https://jsfiddle.net/3g59L4cv/2/</a></p>
  
  <pre><code>        &lt;!DOCTYPE html&gt;
          &lt;html&gt;
          &lt;head&gt;
          &lt;style&gt;
  
          &lt;/style&gt;
          &lt;/head&gt;
          &lt;body&gt;
          &lt;div id="tab"&gt;
  
  
  
            &lt;h3&gt;Section 1&lt;/h3&gt;
            &lt;p&gt; Lorem ipsum dolor sit amet, lectus metus nibh pretium, neque amet nibh dignissim mauris luctus sit, platea ultrices diam interdum lacinia leo at, ante vitae curabitur auctor eget. Ligula purus accumsan nibh dolor, a blandit quisque, feugiat leo condimentum. Pellentesque est adipiscing turpis lacus interdum, enim eros sapien leo diam fermentum, tincidunt magna, integer id pulvinar curabitur et, tortor pellentesque habitasse sit id penatibus. Sed tristique neque diam conubia id, mollis etiam hendrerit libero fringilla nulla, aliquet eget egestas hendrerit non lectus, quos integer lobortis ipsum eu vitae morbi. Mi sed quis dapibus. In turpis ligula fringilla erat tellus, libero ridiculus, donec quis diam, lorem ante consequat a tellus, quae id phasellus mauris suscipit nec nascetur. Convallis cursus neque nec, facilisi sollicitudin donec ante, neque quidem praesent est aenean nisl wisi, eget vestibulum eu, ut ipsum egestas non arcu ea fermentum. Quis pharetra id ut ultricies consectetuer, pretium turpis a arcu, fringilla neque a varius, fermentum duis dolor a fusce molestie morbi, sit nec. Quis et vitae ac sodales lobortis, maecenas mauris dolor ut pede vulputate metus, lacinia mauris eget rhoncus erat pede, luctus ligula augue sodales mauris euismod ut, est est.
  
          &lt;/p&gt;
  
  
  
             &lt;h3&gt;Section 2&lt;/h3&gt;
            &lt;p&gt;Ut bibendum volutpat ac ligula tempus, tristique ac ac rhoncus etiam tincidunt, quis blandit dolor habitant tellus curabitur, amet pede. Donec nascetur, pulvinar elementum fermentum aliquet massa. Tortor quis wisi, tortor non. Vel in. Accumsan phasellus consectetuer tortor pede lorem, pharetra mauris ut et porta, posuere quis, amet lacus tellus vel ac nunc. Integer ut eu dolor arcu nullam, vulputate felis fames leo, vitae lacus dui bibendum est, nam eget. At mi et donec cras, mattis eros in ut, condimentum dolor. Urna elementum vel, nec vivamus, egestas amet ac ultricies, a velit et risus lectus ut, mi turpis dui pharetra massa ligula. Commodo cras quisquam mattis. Orci proin, id vehicula pellentesque proin ligula malesuada, phasellus lorem accusamus nascetur sed. Nisl leo assumenda convallis ut tortor a, libero eu sit nunc augue cras a, justo porta et et mauris, elit laoreet metus placerat lectus feugiat gravida, in eu sed mattis tincidunt magna.&lt;/p&gt;
  
  
  
            &lt;h3&gt;Section 3&lt;/h3&gt;
            &lt;p&gt;Ut bibendum volutpat ac ligula tempus, tristique ac ac rhoncus etiam tincidunt, quis blandit dolor habitant tellus curabitur, amet pede. Donec nascetur, pulvinar elementum fermentum aliquet massa. Tortor quis wisi, tortor non. Vel in. Accumsan phasellus consectetuer tortor pede lorem, pharetra mauris ut et porta, posuere quis, amet lacus tellus vel ac nunc. Integer ut eu dolor arcu nullam, vulputate felis fames leo, vitae lacus dui bibendum est, nam eget. At mi et donec cras, mattis eros in ut, condimentum dolor. Urna elementum vel, nec vivamus, egestas amet ac ultricies, a velit et risus lectus ut, mi turpis dui pharetra massa ligula. Commodo cras quisquam mattis. Orci proin, id vehicula pellentesque proin ligula malesuada, phasellus lorem accusamus nascetur sed. Nisl leo assumenda convallis ut tortor a, libero eu sit nunc augue cras a, justo porta et et mauris, elit laoreet metus placerat lectus feugiat gravida, in eu sed mattis tincidunt magna.&lt;/p&gt;
  
              &lt;h3&gt;Section 4&lt;/h3&gt;
            &lt;p&gt;Ut bibendum volutpat ac ligula tempus, tristique ac ac rhoncus etiam tincidunt, quis blandit dolor habitant tellus curabitur, amet pede. Donec nascetur, pulvinar elementum fermentum aliquet massa. Tortor quis wisi, tortor non. Vel in. Accumsan phasellus consectetuer tortor pede lorem, pharetra mauris ut et porta, posuere quis, amet lacus tellus vel ac nunc. Integer ut eu dolor arcu nullam, vulputate felis fames leo, vitae lacus dui bibendum est, nam eget. At mi et donec cras, mattis eros in ut, condimentum dolor. Urna elementum vel, nec vivamus, egestas amet ac ultricies, a velit et risus lectus ut, mi turpis dui pharetra massa ligula. Commodo cras quisquam mattis. Orci proin, id vehicula pellentesque proin ligula malesuada, phasellus lorem accusamus nascetur sed. Nisl leo assumenda convallis ut tortor a, libero eu sit nunc augue cras a, justo porta et et mauris, elit laoreet metus placerat lectus feugiat gravida, in eu sed mattis tincidunt magna.&lt;/p&gt;
  
  
  
            &lt;h3&gt;Section 5&lt;/h3&gt;
            &lt;p&gt;Ut bibendum volutpat ac ligula tempus, tristique ac ac rhoncus etiam tincidunt, quis blandit dolor habitant tellus curabitur, amet pede. Donec nascetur, pulvinar elementum fermentum aliquet massa. Tortor quis wisi, tortor non. Vel in. Accumsan phasellus consectetuer tortor pede lorem, pharetra mauris ut et porta, posuere quis, amet lacus tellus vel ac nunc. Integer ut eu dolor arcu nullam, vulputate felis fames leo, vitae lacus dui bibendum est, nam eget. At mi et donec cras, mattis eros in ut, condimentum dolor. Urna elementum vel, nec vivamus, egestas amet ac ultricies, a velit et risus lectus ut, mi turpis dui pharetra massa ligula. Commodo cras quisquam mattis. Orci proin, id vehicula pellentesque proin ligula malesuada, phasellus lorem accusamus nascetur sed. Nisl leo assumenda convallis ut tortor a, libero eu sit nunc augue cras a, justo porta et et mauris, elit laoreet metus placerat lectus feugiat gravida, in eu sed mattis tincidunt magna.&lt;/p&gt;
  
              &lt;h3&gt;Section 6&lt;/h3&gt;
            &lt;p&gt;Ut bibendum volutpat ac ligula tempus, tristique ac ac rhoncus etiam tincidunt, quis blandit dolor habitant tellus curabitur, amet pede. Donec nascetur, pulvinar elementum fermentum aliquet massa. Tortor quis wisi, tortor non. Vel in. Accumsan phasellus consectetuer tortor pede lorem, pharetra mauris ut et porta, posuere quis, amet lacus tellus vel ac nunc. Integer ut eu dolor arcu nullam, vulputate felis fames leo, vitae lacus dui bibendum est, nam eget. At mi et donec cras, mattis eros in ut, condimentum dolor. Urna elementum vel, nec vivamus, egestas amet ac ultricies, a velit et risus lectus ut, mi turpis dui pharetra massa ligula. Commodo cras quisquam mattis. Orci proin, id vehicula pellentesque proin ligula malesuada, phasellus lorem accusamus nascetur sed. Nisl leo assumenda convallis ut tortor a, libero eu sit nunc augue cras a, justo porta et et mauris, elit laoreet metus placerat lectus feugiat gravida, in eu sed mattis tincidunt magna.&lt;/p&gt;&lt;/div&gt;
          &lt;input type="button" value="Create PDF"
              id="btPrint" onclick="createPDF()" /&gt;
          &lt;script&gt;
  
  
          function createPDF() {
              var sTable = document.getElementById('tab').innerHTML;
  
              var style = "&lt;style&gt;";
              style = style + "table {width: 100%;font: 17px Calibri;}";
              style = style + "table, th, td {border: solid 1px #DDD; border-collapse: collapse;";
              style = style + "padding: 2px 3px;text-align: center;}";
              style = style + "&lt;/style&gt;";
  
              // CREATE A WINDOW OBJECT.
              var win = window.open('', '', 'height=700,width=700');
  
              win.document.write('&lt;html&gt;&lt;head&gt;');
              win.document.write('&lt;title&gt;Profile&lt;/title&gt;');   // &lt;title&gt; FOR PDF HEADER.
              win.document.write(style);          // ADD STYLE INSIDE THE HEAD TAG.
              win.document.write('&lt;/head&gt;');
              win.document.write('&lt;body&gt;');
              win.document.write(sTable);         // THE TABLE CONTENTS INSIDE THE BODY TAG.
              win.document.write('&lt;/body&gt;&lt;/html&gt;');
  
              win.document.close();   // CLOSE THE CURRENT WINDOW.
  
              win.print();    // PRINT THE CONTENTS.
          }
          &lt;/script&gt;
  
          &lt;/body&gt;
          &lt;/html&gt;
  </code></pre>