What happened
A memo page had an animated GIF in which a bell curve shifts and a correlated-risk hump grows in. Printing to PDF from Chrome captured frame 0: a plain bell curve with no hump.
Fix
- Pick the key frame:
magick in.gif -coalesce f-%02d.pngplusmagick identify -format '%T ' in.gif(the frame with the longest delay is often the designed hold frame). Compress it (pngquant). - Markup: two images, and don't put
loading="lazy"on the print one, or it may not be fetched before printing:
<img class="screen-only" src="/x.gif" loading="lazy" alt="...">
<img class="print-only" src="/x-print.png" alt="...">.print-only { display: none; }
@media print { .screen-only { display: none !important; } .print-only { display: block; } }Page footers without displayHeaderFooter
@page {
size: letter;
margin: 0.75in 0.85in 0.8in;
@bottom-left { content: 'Doc name · example.com/doc'; font: 8pt sans-serif; color: #888; }
@bottom-right { content: counter(page) ' / ' counter(pages); font: 8pt sans-serif; color: #888; }
}Puppeteer: page.pdf({ path, printBackground: true, preferCSSPageSize: true }). Rendered correctly in Chrome for Testing 151.
Other print gotchas
- HTML figures with white text on dark backgrounds lose the background unless
print-color-adjust: exact; -webkit-print-color-adjust: exact;is set. - Use
break-inside: avoidon<figure>andbreak-after: avoidon headings. Usezoom: 0.85on tall HTML diagrams when a figure misses the end of a page by a small amount and leaves a big gap. - Check the output by rasterizing:
pdftoppm -r 50 -png out.pdf p, thenmagick montage(on macOS Homebrew pass-font /System/Library/Fonts/Helvetica.ttcor montage fails with "unable to read font").