Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 554
Jan_V Avatar asked Nov 02 '25 14:11

Jan_V


2 Answers

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/

like image 61
Wolfgang Schreurs Avatar answered Nov 04 '25 05:11

Wolfgang Schreurs


Have you seen these Objects? (PdfDocument - bookmarks - pdfoutline)

It looks like ironpdf supports this functionality by Inserting bookmarks to the Outline (bookmarks property) with the InsertBookMark Method

From my understanding, it might be possible to first render the document, then add bookmarks to the document based on the resulting pages in the pdf... however This could be difficult depending on the nature of the document being generated...

https://ironpdf.com/c%23-pdf-documentation/html/T_IronPdf_PdfOutline.htm

https://ironpdf.com/c%23-pdf-documentation/html/P_IronPdf_PdfDocument_BookMarks.htm

https://ironpdf.com/c%23-pdf-documentation/html/T_IronPdf_PdfDocument.htm

https://ironpdf.com/c%23-pdf-documentation/html/M_IronPdf_PdfOutline_InsertBookMark.htm

like image 41
Matthew Avatar answered Nov 04 '25 06:11

Matthew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!