Pixel-Perfect Invoices
Designer invoice templates need strict layout checks while generating the PDF, so content that would overflow a designer-approved page fails loudly instead of silently reflowing.
Strict layout mode
Use strictLayout when a template has fixed designer-approved bounds:
doc.renderTemplate({
strictLayout: {
maxPages: 1
},
page: {
size: "A4",
margin: 48,
font: "Helvetica",
fontSize: 10,
lineHeight: 13
},
blocks: [
{ type: "heading", text: "INVOICE" },
{
type: "table",
rows: invoiceRows,
options: {
width: 499.28,
columnWidths: [259.28, 50, 95, 95],
headerRows: 1,
cellPadding: 6,
rowGap: 2
}
}
]
});
When strict layout is enabled, renderTemplate() throws PdfEngineError with code === PdfErrorCode.LAYOUT_OVERFLOW if content cannot fit in a fresh page or column. Error details include the block index, block type, page number, available height, and estimated height. Oversized table-row errors also include rowIndex.
Set strictLayout: { oversizedContent: "allow" } only when you want maxPages enforcement without oversized-content failures.
Template discipline
For stable invoice output:
- use fixed page size and margins
- use explicit fonts and font sizes
- set deterministic
infodates and XMP dates - provide explicit table
widthandcolumnWidths - keep tax, rounding, discounts, and currency formatting outside the PDF layer
- fixture-test edge cases such as long customer names, long line items, zero tax, discounts, missing optional fields, and multi-page invoices