Blank pages and empty boxes

Why headless Chrome loses your fonts in a container, what each missing package actually looks like, and the one-line fix.

Symptoms in this page have been reproduced and reported by several teams independently. Where something is unconfirmed, I say so.

You generate a PDF in a Docker container. It comes out completely blank — no text at all, not even English — and Chrome reports no error. Or it comes out with every line in a monospace font that was supposed to be Arial. Or the Chinese and Japanese characters are empty rectangles.

All three are the same root cause, and it is not your CSS.

The worst version. On a slim base image with Chrome's system libraries but no fonts at all, the PDF is a blank page. The text layer does not extract either — so an automated check that greps the PDF for the expected string will not catch it. You have to look at the rendered page.

What each missing package actually produces

This is the useful part: the failure changes shape depending on which piece is missing, so the symptom tells you what to install.

Installed on top of Chrome's libsWhat the PDF looks like
NothingBlank page. No text, no error, and the text layer is empty too.
fontconfig onlyEverything in DejaVu. Latin, Cyrillic, Greek and Arabic print. Emoji, CJK, Hindi and Thai are empty boxes.
fontconfig fonts-liberationArial and Helvetica in Liberation Sans; Times and Georgia in Liberation Serif; Courier in Liberation Mono. Emoji and non-Latin scripts are still boxes.
+ fonts-noto-color-emojiEmoji render in colour.
+ fonts-noto-cjkChinese, Japanese, Korean render.
+ fonts-noto-coreArabic, Hindi, Thai render.

Do not skip fontconfig

--no-install-recommends keeps the image small — and none of the Debian font packages depend on or recommend fontconfig. So it is entirely possible to install fonts and still have no font configuration, which is the thing that tells Chrome that Arial means Liberation Sans.

Without it, two specific failures were reported:

Those images had no /etc/fonts directory at all. Adding fontconfig to the same install line fixed both.

The one-line fix

RUN apt-get update && apt-get install -y --no-install-recommends \
      fontconfig fonts-liberation fonts-noto-color-emoji fonts-noto-cjk fonts-noto-core \
    && rm -rf /var/lib/apt/lists/*

fonts-liberation is what stands in for Arial, Times New Roman and Courier New. The Noto packages add emoji, CJK, and the scripts covered by noto-core. Leave out the ones your documents do not need — but keep fontconfig.

Fonts you never installed fall back without a warning

If your stylesheet asks for Inter and Inter is not in the image, Chrome does not refuse. It prints the text in whatever it falls back to — Liberation Serif, in one test — so a page designed in a sans-serif comes out in a serif.

The cheap mitigation is to end every font list with a generic family:

font-family: Inter, sans-serif;   /* falls back to Liberation Sans, not Serif */

To get the actual font you have two options: install it into the image, or load it with @font-face. If you load it with @font-face and use page.setContent(), relative font URLs do not resolve — you need absolute URLs or base64 data. This catches almost everyone once.

Adding your own font files

COPY fonts/*.ttf /usr/local/share/fonts/

In one test Chrome found a font copied there whether or not fc-cache -f was run afterwards. In CSS, use the font's family name (Lato), not the file name (Lato-Regular.ttf).

The other six failures that look like font problems

These come from the same class of bug — the renderer did not have what it needed at the moment you called it — but the fix is different.

SymptomCauseFix
Colours and shading missingprintBackground defaults to falseSet printBackground: true
PDF says "Loading…" or is blankPrinted before your JS finishedWait for a selector you can name, then print
Relative images brokensetContent has no base URLNavigate to a URL, or use absolute image URLs
Lazy image missingImage never loaded before printingloading="eager", then await img.decode()
Card or row cut at a page edgeBrowser breaks anywhere by defaultbreak-inside: avoid on the block
PDF is about 4× bigger than expectedPuppeteer's tagged defaulttagged: false

The one that is easy to get wrong: waiting

page.pdf() prints what exists at the moment of the call. It does not wait for your JavaScript.

One test built a page that fills its content 1.5 seconds after load. Printing right after goto produced a PDF that said "Loading..." and nothing else. Printing after await page.waitForSelector("#ready") contained the real text. Both Puppeteer and Playwright behaved identically.

So wait for a thing you can name: a selector, a response, or a flag your app sets. networkidle is tempting and has its own problems — it never fires on a page that keeps a connection open, and it fires too early on others.

A note on fonts.ready

Puppeteer's page.pdf() waits for fonts by default. Playwright's documentation does not say it does. One team tried to reproduce a missing webfont by serving it with a 1,500 ms delay and printing immediately — the font was embedded in all six PDFs anyway. So await page.evaluate(() => document.fonts.ready) may be belt-and-braces rather than load-bearing. It costs nothing, so most people call it. I would not rely on it as your only guarantee.

How to check what you actually got

fc-match Arial        # what "Arial" resolves to
pdffonts invoice.pdf  # fonts embedded in the finished PDF

Neither is the whole story:

The only reliable check: print one page containing every script and text style you actually use, then look at it. A text-extraction test passes on a PDF full of empty boxes, because the character codes are still there.

The short version

  1. Install fontconfig plus the fonts you need. Never install fonts without fontconfig.
  2. End every font list with a generic family.
  3. printBackground: true, always.
  4. Wait for a named selector before printing, not for a timeout.
  5. Look at the PDF. Do not grep it.

If you generate documents rather than read them

I also wrote up the seven layout defects that hit HTML invoices — table headers vanishing on page two, totals splitting across a page break, A4 printed as Letter. Each with the CSS that fixes it.

Read the layout guide Open the PDF generator

Free, and staying free

The tool is MIT licensed with no paywall, no account and no telemetry. Download it, read the source, change it, ship it inside your own product. No attribution required.

Want this built for you?

Reading this because your invoice printed wrong. I build print-exact A4 PDF templates — selectable text, embedded fonts, tables that paginate with repeated headers. $150 fixed, 3 days.

Order the template build →

Or try the free generator first: generator.html

Get the template

Two versions, both MIT licensed, both run entirely in your browser with no data leaving the machine.

Free template
One HTML file, edit by hand. Pay what you want.
Full generator — $19
Form input to PDF, source + sample + docs.