Skip to content
Windows Server Running · 7 min read

Printing a Website on A3: The PDF Was Right, the Print Came Out A4

Full-page headless Chrome capture, sliced into a 300 dpi A3 PDF. Then it printed A4 anyway. Check the PDF MediaBox and the printer driver default.

Task of the day: "print the website on A3". A client wanted the current draft of their site on paper. Not a screenshot on a phone, a proper A3 printout of the desktop layout, top to bottom, plus two subpages.

I built the PDF, opened it, handed it over. A bit later: "he printed it as A4...".

The PDF was fine. The printer setup wasn't. This post covers both halves: how I turned a long web page into a clean multi-page A3 PDF, and how to prove in two minutes whether an "it came out A4" problem is the file or the print path.

TL;DR: Capture the page with headless Chrome over the DevTools protocol at 1440 px wide and device scale 2, with lazy images forced to eager and reduced motion on. Slice the tall PNG into A3 pages at 300 dpi with Pillow, breaking only at section boundaries. If it prints A4 anyway: read the /MediaBox from the PDF (A3 portrait is about 842 × 1191 pt), then check Get-PrintConfiguration on the printers. In my case the A3 printer's driver defaulted to Letter and the other printer only does A4. Fix in the print dialog: right printer, paper A3, "Actual size" instead of "Fit".

Why a screenshot and not "Print to PDF"

The obvious route is Chrome's own print to PDF with @page { size: A3 } or paperWidth/paperHeight on Page.printToPDF. I didn't do that, on purpose. Print mode reflows the page to the paper width and applies whatever print CSS the site has (or doesn't have). The client wanted to see the desktop layout, the thing they look at in the browser. So: render at a real desktop width, take one tall screenshot, put that on paper.

For completeness, the print route would look like this (A3 in inches is 11.69 × 16.54):

// alternative I did NOT use: let Chrome paginate
await send('Page.printToPDF', {
  paperWidth: 11.69, paperHeight: 16.54,
  printBackground: true, preferCSSPageSize: false,
});

Fine for documents. For "show me the website as it looks", the layout changes under you.

The capture

Plain Node (24 has fetch and WebSocket built in), Chrome headless, talking CDP directly. No Puppeteer, nothing to install. The important part:

const proc = spawn(chrome, ['--headless=new', `--remote-debugging-port=${port}`,
  `--user-data-dir=${prof}`, '--hide-scrollbars', '--no-first-run', 'about:blank']);
// ... connect to the page target's webSocketDebuggerUrl ...

await send('Page.enable');
await send('Emulation.setEmulatedMedia', {
  features: [{ name: 'prefers-reduced-motion', value: 'reduce' }] });
await send('Emulation.setDeviceMetricsOverride',
  { width: 1440, height: 900, deviceScaleFactor: 2, mobile: false });
await send('Page.navigate', { url });
// wait for Page.loadEventFired, then fonts
await evalJS('document.fonts.ready.then(()=>1)');

// lazy images -> eager, wait until all are loaded
await evalJS(`(async()=>{document.querySelectorAll('img[loading=lazy]').forEach(i=>i.loading='eager');
  await Promise.all([...document.images].map(i=>i.complete?1:new Promise(r=>{i.onload=i.onerror=r})));return 1})()`);

// grow the viewport to the full page height, twice (height changes once images land)
let h = await evalJS('Math.ceil(document.documentElement.scrollHeight)');
await send('Emulation.setDeviceMetricsOverride', { width: 1440, height: h, deviceScaleFactor: 2, mobile: false });
// ... sleep, wait for images again, re-measure, set again ...

// remember where sections start, for page breaks later
const breaks = await evalJS(`[...document.querySelectorAll('body > *, main > *, section, header, footer')]
  .map(e=>Math.round(e.getBoundingClientRect().top+scrollY)).filter(y=>y>0)`);
const shot = await send('Page.captureScreenshot', { format: 'png' });

Instead of scrolling and stitching, the viewport simply becomes the full page height. One capture, no seams. The main page came out at 1440 × 8128 CSS px, which at scale 2 is a 2880 × 16256 PNG. The two subpages were around 2560 CSS px tall each.

Gotcha: lazy images and scroll animations

A headless browser that never scrolls never triggers loading="lazy" or IntersectionObserver reveals. The main page had 44 lazy images. Without forcing them to eager you get grey boxes on half the printout.

The site also had a "pen draws an underline when the heading scrolls into view" animation. Its script bails out early when prefers-reduced-motion: reduce is set, so emulating that media feature gives you the final, fully drawn state. Check your site's JS for something similar before you start hacking classes.

Gotcha: vh units when the viewport is 8000 px tall

Making the viewport as tall as the page has one trap: anything sized in vh now scales with an 8000 px viewport. A min-height: 100vh hero turns into a monster. I grepped the CSS for vh first. Only hit was a 70vh max-height on a modal dialog, which never shows in the capture. If you have a full-height hero, pin it to a pixel height for the capture or this approach falls apart.

Slicing into A3 pages

A3 portrait at 300 dpi is 3508 × 4961 px. 10 mm margins left, right and top, 16 mm at the bottom for a small footer line with page name, date and page number.

DPI = 300
MM = DPI / 25.4
PW, PH = round(297 * MM), round(420 * MM)        # 3508 x 4961, A3 portrait
MX, MT, MB = round(10 * MM), round(10 * MM), round(16 * MM)
CW, CH = PW - 2 * MX, PH - MT - MB

s = im.width / CW            # source px per output px
maxh = int(CH * s)           # how much source fits on one sheet
while y < im.height:
    end = y + maxh
    if end >= im.height:
        end = im.height
    else:
        # break at the last section start that still fills >= 60 % of the sheet
        cands = [b for b in breaks if y + maxh * 0.6 <= b <= end]
        if cands: end = max(cands)
    ...
pages[0].save(out, save_all=True, append_images=pages[1:], resolution=DPI)

The resolution=DPI on the save matters. Pillow uses it to compute the PDF page size, so 3508 px at 300 dpi becomes 297 mm. Leave it at the default and your "A3" page is a different physical size.

First run: 9 pages. The short subpages each spilled a sliver onto a second sheet. Second pass: if a page is at most 1.35× one sheet tall, scale it down to fit one sheet and center it. That got it to 7 pages: the main page on 5 (breaks always between sections, nothing cut through an image), plus one sheet per subpage. About 14 MB.

I checked it with a contact sheet of all pages before handing it over. Then opened it, wrote "set A3 and Actual size / 100 %" next to it, done. Or so I thought.

"He printed it as A4"

First question: is it the file or the print path? Don't guess, read the PDF. PowerShell, no extra tools:

$b = [IO.File]::ReadAllBytes("C:\print\site_A3.pdf")
$t = [Text.Encoding]::ASCII.GetString($b)
([regex]::Matches($t, '/MediaBox\s*\[[^\]]*\]') | Select-Object -First 2).Value
/MediaBox [ 0 0 841.92 1190.64 ]

PDF units are points, 1/72 inch. A3 is 841.89 × 1190.55 pt. The tiny difference is pixel rounding. The file is A3. (A4 would be about 595 × 842.)

So the print path. What printers are there, and what paper do their drivers default to?

Get-Printer | Select-Object Name, DriverName, PortName | Format-Table -AutoSize
Get-CimInstance Win32_Printer | Where-Object Default | Select-Object Name
Get-Printer | ForEach-Object {
  try { $c = Get-PrintConfiguration -PrinterName $_.Name -ErrorAction Stop
        "$($_.Name): $($c.PaperSize)" } catch {}
}

Two real printers showed up, both connected via WSD with Microsoft's generic class drivers:

  • the default printer, a big office MFP that can do A3, on the "Microsoft OpenXPS Class Driver 2", default paper size: Letter
  • a small laser MFP on the "Microsoft IPP Class Driver", default A4, and it can't do A3 at all

Either way you get a small print. Send it to the A4 box and the viewer shrinks it to A4. Send it to the A3 box without touching the dialog and the driver says Letter, the viewer's "fit" logic shrinks it to Letter. Nobody gets an error, the page just comes out small.

Gotcha: the print log is off by default

I wanted to see which printer actually got the job. Microsoft-Windows-PrintService/Operational would tell you (event 307 is "document printed", with the printer name and page count), but that log is disabled by default on Windows, so it was empty. If you support printing for people, turn it on before the next complaint:

wevtutil sl Microsoft-Windows-PrintService/Operational /e:true

Then Get-WinEvent -LogName 'Microsoft-Windows-PrintService/Operational' | Where-Object Id -eq 307 answers "which printer, which job" next time.

The fix

Nothing to change in the file. In the print dialog:

  1. Pick the A3-capable printer explicitly, not whatever is default.
  2. Paper size A3. Often hidden under "Properties", "Page setup" or "More settings".
  3. Size: Actual size / 100 %, not "Fit to page" / "Shrink oversized pages".
  4. Orientation portrait.

If the dialog doesn't offer A3 at all: generic class drivers sometimes expose only a short list of paper sizes. Install the vendor's real driver, or skip the PC entirely and print from a USB stick at the device. Setting the driver default to A3 permanently is also possible (Set-PrintConfiguration -PrinterName "..." -PaperSize A3), but on a shared office printer I'd rather not change everybody's default for one job.

What I'd do differently

Put the paper size in the file name and in the footer of every page ("A3, print at 100 %"). The person at the printer doesn't read your chat message, they see a PDF and hit Ctrl+P. And whenever a print "comes out wrong": MediaBox first, printer config second. Two commands, and you know which side to fix instead of rebuilding a perfectly good PDF.

If you're rendering HTML to PDF in a pipeline rather than for paper, I wrote up the Playwright route for HTML receipts, which uses page.pdf() with a fixed format. More PowerShell one-liners like the printer checks above are in my PowerShell sysadmin cheatsheet, and for PDFs that are only images inside, see scanned PDFs and vision tools.


Related posts