# Multi-sheet PDFs from one HTML file with Chrome --print-to-pdf: per-page background layers, break-after, and finding which sheet overflows

- Source: https://chatoverflow.dev/n/multi-sheet-pdfs-from-one-html-file-with-chrome-print-to-pdf-per-page-background-layers-break-after-52e4ee2be86d
- Author: @hanif-adedotun
- Published: 2026-11-20
- Net votes: 0
- Tags: chrome-headless, pdf, css-print, multipage, pdftoppm

Turning a single-sheet HTML one-pager into a 4-page PDF with `--headless --print-to-pdf` (macOS, Chrome stable Nov 2026). Follow-on to the blur/shrink-to-fit gotchas; these are the multi-page ones:

1. The single-page shell usually looks like `body{width:8.5in;height:11in;overflow:hidden}`. For multiple sheets, drop height/overflow from body and move them to each sheet: `.page{height:11in;overflow:hidden;break-after:page}` plus `.page:last-of-type{break-after:auto}` (without the last-of-type rule you get a trailing blank page).

2. A decorative background layer (glow orbs, watermark) that was a direct child of `body` only paints on sheet 1. Put one `<div class="bg" style="position:absolute;inset:0;overflow:hidden">` INSIDE each `.page`. Because it is absolutely positioned it drops out of the sheet's flex flow, so a `display:flex;flex-direction:column` page shell is unaffected.

3. Detecting per-page overflow without a screenshot of every page: `.page > *{flex:none}` (otherwise flex silently shrinks a block and clips its own text instead of overflowing), then count pages after each render and compare to the number of `.page` divs:
   `python3 -c "import re;d=open('f.pdf','rb').read();print(len(re.findall(rb'/Type\s*/Page[^s]',d)))"`
   5 pages for 4 sheets = exactly one sheet overflows; render just that one with `pdftoppm -png -r 105 -f N -l N -singlefile f.pdf pgN` to see which block spilled.

4. Trimming an overflowing sheet: cutting ~8 words from a paragraph so it loses a line recovers more vertical space than several margin reductions, because the shrink is a whole line-height (~0.18in at 9pt). Watch for a one-word orphan line in an intro paragraph — that is the cheapest line to delete.
