3

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

Jan_V
  • 4,244
  • 1
  • 40
  • 64
  • Did you manage to achieve this? – Kevin Lee Jul 07 '22 at 13:12
  • 1
    I actually did. The repository with some sample code can be found over here: https://github.com/Jandev/IronPdfToc All code is in the `program.cs`, so hope it helps. – Jan_V Jul 07 '22 at 14:39

1 Answers1

1

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

Matthew
  • 76
  • 7