Why headless Chrome loses your fonts in a container, what each missing package actually looks like, and the one-line fix.
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.
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 libs | What the PDF looks like |
|---|---|
| Nothing | Blank page. No text, no error, and the text layer is empty too. |
fontconfig only | Everything in DejaVu. Latin, Cyrillic, Greek and Arabic print. Emoji, CJK, Hindi and Thai are empty boxes. |
fontconfig fonts-liberation | Arial 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-emoji | Emoji render in colour. |
+ fonts-noto-cjk | Chinese, Japanese, Korean render. |
+ fonts-noto-core | Arabic, Hindi, Thai render. |
--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:
fonts-liberation alone, every line came out in Liberation Mono — including the text that was set in Arial and Times New Roman.monospace, which lost its fixed width.Those images had no /etc/fonts directory at all. Adding fontconfig to the same install line fixed both.
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.
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.
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).
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.
| Symptom | Cause | Fix |
|---|---|---|
| Colours and shading missing | printBackground defaults to false | Set printBackground: true |
| PDF says "Loading…" or is blank | Printed before your JS finished | Wait for a selector you can name, then print |
| Relative images broken | setContent has no base URL | Navigate to a URL, or use absolute image URLs |
| Lazy image missing | Image never loaded before printing | loading="eager", then await img.decode() |
| Card or row cut at a page edge | Browser breaks anywhere by default | break-inside: avoid on the block |
| PDF is about 4× bigger than expected | Puppeteer's tagged default | tagged: false |
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.
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.
fc-match Arial # what "Arial" resolves to
pdffonts invoice.pdf # fonts embedded in the finished PDF
Neither is the whole story:
fc-match needs fontconfig, and it does not always agree with Chrome. It answered "Noto Sans" for Inter in one test while Chrome printed that text in Liberation Serif.pdffonts lists most fonts, but Chrome embeds colour emoji and CJK as Type 3 fonts, which it shows as [none].fontconfig plus the fonts you need. Never install fonts without fontconfig.printBackground: true, always.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 generatorThe 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.
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
Two versions, both MIT licensed, both run entirely in your browser with no data leaving the machine.