What is a headless Chromium PDF rendering?

Headless Chromium PDF rendering is the process of using the Chromium browser engine, run without a visible UI ("headless"), to load a page — its HTML, CSS, fonts, and JavaScript — and export the fully rendered result as a PDF file, the same way a real browser's "Print to PDF" would.

Expanding on the concept

Chromium is the open-source browser engine behind Google Chrome, Microsoft Edge, and several other browsers. In "headless" mode, it runs as a background process with no window, mouse, or keyboard — it's driven entirely by code. That makes it useful as a general-purpose rendering engine on a server: give it HTML or a URL, let it lay out and paint the page exactly as it would on a screen, and instead of displaying the result, capture it as a screenshot or, in this case, a paginated PDF document. Because it's the real browser engine, it supports the full web platform — modern CSS (flexbox, grid, `@page` rules), web fonts, and JavaScript that runs before the page is captured.

How it works

A typical headless Chromium PDF pipeline follows the same few steps regardless of which tool or library drives it:

  1. Launch a headless Chromium process (no visible window).
  2. Navigate it to a URL, or load raw HTML directly into the page context.
  3. Wait for the page to finish loading — including any client-side JavaScript rendering.
  4. Call Chromium's print pipeline (the DevTools Protocol's Page.printToPDF command) with options like page format and margins.
  5. Receive back a PDF file and return or store it.

Docweave's own API follows exactly this shape:

curl https://docweave.dev/api/v1/pdf \
  -H "Authorization: Bearer dw_live_your_key" \
  -H "Content-Type: application/json" \
  -H "Accept: application/pdf" \
  -d '{
    "source": { "type": "url", "url": "https://example.com/invoice/1024" },
    "options": { "format": "A4", "margin": "20mm" }
  }' \
  --output invoice.pdf

How Docweave relates to this

Docweave is a document-generation API built directly on headless Chromium rendering. A single call to POST /api/v1/pdf accepts a source — raw HTML, a URL, or a stored template combined with JSON data — renders it with Chromium, and returns the PDF, billed per document rather than per page. Requests can carry an idempotencyKey so retries never generate the same document twice. The same rendering path is also exposed as an open-source MCP tool — run npx @docweave/mcp — so an AI agent can call generate_pdf directly instead of writing HTTP plumbing.

FAQ

What does 'headless' mean in headless Chromium?

Headless means the Chromium browser runs without a visible window or display — it still parses HTML, runs JavaScript, applies CSS, and lays out the page exactly as a normal browser would, but it does so in the background on a server.

Is headless Chromium PDF rendering the same as 'print to PDF'?

It uses the same underlying engine. Chromium's DevTools Protocol exposes a Page.printToPDF command that performs the same layout-and-paginate work as choosing Print > Save as PDF in the Chrome browser, but it's called programmatically instead of by a person clicking a menu.

Why use headless Chromium instead of a non-browser PDF library?

Libraries that build PDFs directly (without a browser) typically support a limited subset of CSS and JavaScript, so complex layouts, web fonts, flexbox/grid, or client-side rendering can break. Headless Chromium renders the actual web platform, so if a page looks right in Chrome, it generally prints right as a PDF too.

What are the trade-offs of headless Chromium PDF rendering?

It's heavier than a pure PDF library — you're running a full browser process, which costs more memory and startup time — and because it can fetch arbitrary URLs or execute arbitrary HTML, it must be run with SSRF and sandboxing protections in production.

Try the MCP-native PDF API.

Get an API key