Search code examples
c#htmlpdfhandlebars.jsironpdf

Generate a table of contents in HTML with IronPDF


We're in the process of generating a PDF file, using IronPDF, from some HTML we've generated.

This document will contain an unknown number of pages. Aside from showing the page number at the bottom of the, which we can probably fix using the {page}`-placeholder, we also need a Table of Contents at the beginning of the document.

While this is probably doable, I fail to see how we should go about implementing something like this. We only have the generated HTML to our disposal, so it's hard to come up with page numbers upfront.

I'm guessing using the 'Advanced Templating With Handlebars.Net' functionality can be (mis)used for this scenario, but I'm struggling to get my head around this.

Any suggestions or pointers on how I can proceed in adding a table of contents at the beginning of a document (created from HTML)?


Solution

  • These days it's a bit easier to add a table of contents with IronPdf when generating a PDF from HTML, see: https://ironpdf.com/how-to/table-of-contents/