printpipe.io
Docs: PDF layout

PDF layout

Print CSS that paginates cleanly, headers and footers with page numbers, and password-protected PDFs.

Print CSS tips

A starting point for documents that paginate cleanly. Send it with "media": "print":

@page { size: A4; margin: 16mm 14mm; }

/* Keep colours and backgrounds exactly as designed. */
html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

/* Start each chapter on a new page; never split these blocks. */
.chapter { break-before: page; }
figure, tr, .card { break-inside: avoid; }

/* Keep headings with the paragraph that follows. */
h1, h2, h3 { break-after: avoid; }

/* Repeat table headers on every page. */
thead { display: table-header-group; }

/* Fewer orphaned lines at page ends. */
p { orphans: 3; widows: 3; }
  • Use @page and @media print CSS with "media": "print" for print-specific layouts.
  • Control page breaks with break-before, break-after and break-inside: avoid.
  • Web fonts (Google Fonts or @font-face) work; they are loaded before printing.
  • Content drawn by JavaScript after load needs waitFor. URLs are scrolled through first, so images that load on scroll appear; for HTML that does this, set lazyLoad to true.
  • Cookie banners on URLs are accepted first, so they don't cover the page. Set acceptCookies to false to keep them.
  • Pages can only reach the public internet: local, private and cloud-internal addresses are blocked.
  • With singlePage (Basic, Plus, Pro and Enterprise), very tall pages are capped at 200 inches, the largest page Acrobat opens.

Headers & footers

BasicPlusProEnterprise

Templates are small HTML documents printed in the page margins, so set margins large enough. Use the classes pageNumber, totalPages, date, title and url. Templates don't inherit page styles: set font sizes inline, and use data: URIs for images.

{
  "html": "https://example.com/report",
  "marginTop": 60,
  "marginBottom": 60,
  "headerTemplate": "<div style='font-size:9px; width:100%; text-align:center'><span class='title'></span></div>",
  "footerTemplate": "<div style='font-size:9px; width:100%; text-align:right; padding-right:20px'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>"
}

Encryption

BasicPlusProEnterprise

Setting userPassword or ownerPassword encrypts the PDF with AES-256. Without the owner password, readers may only do what permissions allows (default: print).

{
  "html": "<h1>Payslip</h1>",
  "userPassword": "opens-the-file",
  "ownerPassword": "lifts-restrictions",
  "permissions": ["print"]
}