Issue
The HTMLToPDF function dynamically resizes the PDF file content based on the table size, affecting the output layout.
Symptoms and Impact
The HTMLToPDF function dynamically resizes the PDF file content based on the table size during the conversion process.
When the PDF file is generated in the HTML code through a Correspondence rule and then converted using the HTMLToPDF function, the content scaling behavior is not maintaining the expected fixed dimensions but instead adjusts proportionally to the table size present in the PDF file.
The dynamic resizing behavior affects the consistency and formatting of the generated PDF output, as the PDF file content dimensions should remain constant regardless of the table size contained within the correspondence.
Steps to Reproduce
-
Create a Correspondence rule with a table containing a variable number of columns/rows.
-
Configure an HTMLToPDF conversion activity that references the correspondence rule.
-
Generate a PDF file using a small table (e.g. 3 columns, 5 rows). Result: the document content appears at one size/scale.
-
Generate a PDF file from the same correspondence rule using a large table (e.g., 10 columns, 20 rows). Result: the document content shrinks/scales to accommodate the larger table.
-
Compare the two PDF files — content dimensions differ based on table size. Key observation: the entire document content (not just the table) scales proportionally to fit the table, rather than the table adapting within fixed document dimensions.
Root Cause
This is a limitation of HTMLtoPDF rendering when flexible HTML is converted to a fixed medium.
HTMLToPDF applies automatic shrink‑to‑fit logic when rendering PDF content to prevent tables or text from being clipped.
If any table or unwrapped content exceeds the printable width of the (PDF file) page, the PDF engine converts responsive HTML into a fixed-size layout and applies shrink‑to‑fit logic to prevent table content from being clipped.
This is a known limitation of HTMLtoPDF conversion and can be mitigated by using fixed‑width layouts and PDF‑specific styling.
As a result, wider tables cause the entire PDF file to scale during PDF generation.
-
PDF files generated from Correspondence (HTML) often rely on modern CSS
-
Layouts are responsive by default
-
Tables frequently use percentage or auto widths
Unlike UI rendering in the browser, PDF rendering has no viewport, so responsive rules collapse into size calculations making table width the dominant factor.
Solution
To address this behavior, employ a CSS- and configuration-based solution that constrains table dimensions and ensures fixed layout rendering during PDF generation.
Options:
-
Option 1: Force fixed table widths using CSS to prevent dynamic resizing
-
Option 2: Constrain the printable width explicitly in your HTML structure
-
Option 3: Apply PDF-specific CSS using @media print rules with table-layout: fixed and defined widths
-
Option 4: Adjust HTMLtoPDF parameters through the pyPDFSettings Data Transform as documented in the Pega Platform documentation.
Details
Option 1. Force fixed table widths
<table style="table-layout: fixed; width: 100%; max-width: 650px;">
<colgroup>
<col style="width: 30%">
<col style="width: 70%">
</colgroup>
</table>
Option 2. Constrain the printable width explicitly
<div style="width: 670px; max-width: 670px;">
<!-- letter content -->
</div>
Option 3. Use PDF‑specific CSS
@media print {
table {
table-layout: fixed;
width: 100%;
}
body {
font-size: 11pt;
}
}
For more details see Modifying presentation options of the non-optimized table layout
Option 4. Adjust HTMLtoPDF parameters
There are some settings in the Data Transform pyPDFSettings to adjust HTMLtoPDF parameters.
For more information see HTMLtoPDF parameters.
References
Modifying presentation options of the non-optimized table layout