Question

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.

***Moderator Edit: Vidyaranjan | Updated Categories***

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

Pega
May 16, 2016 - 7:50am

Hi Rajendra,

you can take a look at this discussion for some inputs on this : Re: PDF Page Count

May 16, 2016 - 8:18am
Response to Santanu

Hi Santanu,

Thanks for your reply, However I am looking for the way how can we generate the table of contents with the page numbers for a pdf document which I am creating through the HTML code.

Pega
May 16, 2016 - 9:05am
Response to RAJENDRA75

Hi Rajendra,

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

It should be easier to influence the PDF document structure using PDFBox; see this third party post for instance : http://stackoverflow.com/questions/23553094/pdfbox-how-to-create-table-of-contents

Thanks,

John

*It does of course allow tables (in genereal) to be specified: but no semantics which allow you to label a structure in a document as being 'this is a [dynamic?] table of contents'

March 8, 2017 - 7:21am

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.

A sample code piece....

<html>
<head>
<style>
.ptoc1-style-left, .ptoc1-style-right{  
color:#004581; 
font-weight:bold;  
}  
.ptoc-table{
border-collapse:separate;
    border-spacing:15px 15px;
}
</style>
</head>
<body>
<pega:include name="TitlePage" type="Rule-HTML-Paragraph"></pega:include>
<pd4ml:page.break>
<p style= "color:#004581; font-size:25px; font-weight:900">Contents</p>
<pd4ml:toc>
<pd4ml:page.break>
<h1 style= "color:#004581"> 1 Introduction</h1>
<pega:include name="Introduction" type="Rule-HTML-Paragraph"></pega:include>
<pd4ml:page.break>
<h1 style= "color:#004581"> 2 Second section</h1>
<pega:include name="Second section" type="Rule-HTML-Section"></pega:include>
<pd4ml:page.break>
<h1 style= "color:#004581"> 3 Third Section</h1>
<pega:include name="thirdSection" type="Rule-HTML-Section"></pega:include>
<pd4ml:page.break>
<h1 style= "color:#004581"> 4th Fourth section</h1>
<pega:include name="Fourthsection" type="Rule-HTML-Section"></pega:include>
</body>
</html>

 

March 8, 2017 - 7:27am

Header and footer page number can be easily achieved. HTMLToPDF activity takes these as parameter.

param.pyPDFHeaderHTMLTemplate for header and param.pyPDFFooterHTMLTemplate for footer.

you can populate this parameter using a HTML stream and by calling property-set-Html. Inside your HTML stream, if you need page number you can use reference $[page]. Sample code for footer.

<div style="font-size:11px;border-top:3px solid #23A2DC"> <div style ="float:left; padding:2px"> footer text</div><div style="background-color:#23A2DC;padding:5px;float: right">$[page]</div></div>