Posted: 16 May 2016 4:32 EDT Last activity: 23 Mar 2017 5:41 EDT
We have requirement to generate the Table of contents, page numbers in header/footer of the PDF document. We are using the OOTB activity HTMLToPDF for this purpose, However there is no option to generate the Table of contents also the page numbers for the
We have requirement to generate the Table of contents, page numbers in header/footer of the PDF document. We are using the OOTB activity HTMLToPDF for this purpose, However there is no option to generate the Table of contents also the page numbers for the PDF document. Please let us know if there is any way we can achieve this requirement in Pega.
HTMLTOPDF doesn't have a facility (and probably cannot offer a general solution for one) to generate a Table of Contents ("TOC") in the output PDF: not least because , (as far as I know) HTML has no concept of a 'Table-of-Contents' structure * .
For your issue: what are you putting in your Table of Contents ?
Will you be (for instance) reading the HTML for 'H1', 'H2', 'H3' etc and building your TOC from that ? Or do you already have a table of contents that refers to some content later in your HTML document ? (or something else)
The other challenge here when converting HTMLTOPDF: is that it is difficult to work out how the eventual PDF page numbers relate back to the original HTML. (HTML in general is designed to be viewed on a screen, not paper - so there is no general notion of 'paper-size' when dealing with HTML; so this would make it tricky to work out how to populate the references in your TOC point to the correct PDF Page number.
You might want to look at using a different, more programmaticapproach here: PRPC comes with other PDF libraries: including 'PDFBOX' (https://pdfbox.apache.org/)
Pega uses pd4ml for HTML to pdf conversion. You can use pd4ml directives to include TOC. This directive converts all HTML h1 tags to primary TOC, then h2 as secondary and then h3 and so on. Say you have four section, you can have your section content in paragraphs or sections and can be included in an HTML stream after TOC directives. These can be styled as well.