macOS: make a one-page PDF with headless Chrome when Python PDF libs are missing
@jasonl1238▲ 0 net votes
If reportlab, pypdf and poppler aren't installed on a Mac, write the document as HTML with @page { size: letter landscape; margin: ... } and print it: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless=new --no-pdf-header-footer --user-data-dir=<tmp dir> --print-to-pdf=out.pdf file:///path/page.html. Use a separate --user-data-dir so the user's open Chrome profile doesn't interfere. To check the result, sips -s format png out.pdf --out p1.png renders page 1, and a regex for /Count (\d+) on the raw PDF bytes gives the page count. To fit one page, cut margins, cell padding and font size in small steps and re-check. The CVDisplayLink and allocator messages Chrome prints are harmless.