Hi everyone,
We are currently generating PDFs using an HTML‑to‑PDF approach. The content of these letters is highly dynamic and assembled using a combination of data types and paragraph rules. For one of our use cases, we need to dynamically reference the previous page number within the body content.
We are successfully printing page numbers in the PDF footer using PD4ML functions. However, when we attempt to use the same page‑numbering function within the HTML body, it does not work.
Example:
If a particular paragraph appears on page 10, we need to insert a reference to page 9 (i.e., the number of preceding pages). These page numbers are not static since the paragraph’s position can shift depending on the amount of data included in the letter.
Sample text:
“Please refer to the schedule listed on this page and the preceding pages.”
Any guidance, suggestions, or recommended solutions would be greatly appreciated.
Please note that these are legal wordings, and the business is hesitant to modify them—hence my inquiry to see if anyone has implemented something similar.
Many thanks in advance,
Mohan P
Hello @MohanP17614142 Firstly welcome to the forums 
If i understand correctly, your requirement is to navigate between the PDF page using the reference links. For eg. In page 4, you have a link “Go to Page 9“ and onclick of that you should navigate to page 9. Is that so?
Usage of HTML Anchors
The HTMLToPDF engine used by Pega preserves internal anchor links (#id) and converts them to PDF internal navigation.
Example HTML
<!-- Page 4 -->
<div style="page-break-before: always;">
<h2 id="page4">Page 4</h2>
<p>This is Page 4 content.</p>
<a href="#page7">Go to Page 7</a>
</div>
<!-- Page 7 -->
<div style="page-break-before: always;">
<h2 id="page7">Page 7</h2>
<p>This is Page 7 content.</p>
<a href="#page4">Move to Page 4</a>
</div>
How it works
id="page4" creates an internal anchor.
href="#page4" creates a link to that anchor.
- When Pega converts HTML → PDF, the link becomes a PDF GoTo action.
Result in the generated PDF:
- Page 7 → “Move to Page 4” → navigates to Page 4
- Page 4 → “Go to Page 7” → navigates back to Page 7
Only thing is that you have ensure that the page number which you put on the link should be dynamic in nature depending on the content you have. You could do some mapping kind of stuff based on certain fields placed in the PDF before you generate the PDF. Not sure how you are sourcing the content for the PDF (Through Section or through HTML)
If you want to use iText or PDFBox to generate the PDF’s dynamically, you can make use of the Annotations link facility to achieve the same.
Below is a sample PDF generated for the same.
internal-navigation-demo.pdf (4.6 KB)
See if this is what you were expecting.
Regards
JC
Hi Jayachandra,
Thanks for taking time to answer this, appreciate it!
We have to print a line in the body of a pdf which prints count of total number of preceding pages.
Please note this paragraph can appear on any page number based on dynamic content available for the template. Couple of examples below:
- If paragraph is on page 5 - then it should say “Please refer to the schedule listed on this page and the preceding ‘4’ pages.”
- If paragraph is on page 8 - then it should say “Please refer to the schedule listed on this page and the preceding ‘7’ pages.”
We have to insert ‘count of preceding pages’ in the paragraph text.
When you generate PDF using HTMLToPDF, you can only send the information which you have configured using Section or HTML w.r.t the markup into the PDF.
However, for inserting specific information in certain pages based on conditions would involve manipulating the PDF using external packages like iText(com.lowagie) or PDFBox.
So just a vague idea for you to explore.
While you generate the PDF using section or html, insert tags in your content with certain unique ID’s for the text to be placed so that at a later point of time you can identify them. As an alternative, you can try the eForm PDF with editable fields as well (Not sure if you are using templates to generate the PDF’s) with editable fields in each page with uniqueID for identification.
Once the PDF is generated using HTMLToPDF utility, take the base64 encoded string and send it to a new utility function where you can use the external packages to load/open the PDF. Parse through the list of pages and map/compare your conditions and insert your content in the tag or the eForm field. Once it is done, you can flatten the field and generated the updated PDF and later attach it to the case or do whatever follows.
As i have already worked on both eForm and Section/HTML to generated PDF’s along with PDFBox and iText packages, i am sure the above approach is possible, but we have to try it to see.
Hope this helps to start exploring.
Regards
JC