Skip to content

Why headless browsers fail at production PDFs

Headless Chrome was built for viewports, not paginated documents. Here is why HTML-to-PDF pipelines drift, leak memory, and break at batch scale.

Composa Team6 min read

Almost every engineering team starts PDF generation the same way: spin up headless Chrome with Puppeteer, render a React or HTML route, and call page.pdf(). On a single local invoice, it works in twenty minutes. Six months later, that decision turns into a quiet tax on memory, design quality, and deploy velocity.

Browsers think in scrollbars, not pages

HTML and CSS were designed for continuous viewports that reflow whenever a window resizes. A printed or downloadable customer document follows opposite rules: fixed physical dimensions (A4, Letter, A5, exact millimeter labels), running headers and footers, widow and orphan control, and tables that break cleanly across page boundaries.

When you force Chromium to simulate pagination with @media print, small data variations trigger surprising layout regressions:

  • A client name wraps onto a second line and pushes a total block onto an almost empty trailing page.
  • A chart container clips mid-axis because flexbox and grid fragmentation behave differently across Chromium versions.
  • A clearing barcode or shipping label shifts by two millimeters when DPI scaling or default browser margins change.

Because those failures depend on real customer payloads, unit tests rarely catch them. Customers report them first.

The hidden operational cost of browser fleets

Running Chromium in production means managing a full browser engine just to compile static documents. Each browser context consumes hundreds of megabytes of RAM, and long-lived pools accumulate leaked pages, zombie processes, and font-cache drift across Linux containers.

Scaling that pipeline for month-end billing, cohort transcripts, or 50,000 personalized portfolio reviews requires worker queues, container restarts, custom font bundles baked into Docker images, and retry choreography when Chromium crashes mid-batch.

You end up maintaining browser infrastructure even though your product only wanted a deterministic file from JSON.

Separating layout from application deploys

There is a second problem with HTML-to-PDF that rarely shows up in architecture diagrams: ownership. When a document template lives as React JSX inside your web repo, every copy tweak from Legal, every typography refinement from Design, and every chart label update from Data Science requires a pull request and a production deploy.

Product teams avoid improving customer-facing documents because touching print CSS feels fragile. As a result, invoices, statements, and executive reports stay stuck in 2014 styling long after the rest of the product has matured.

What changes with a native page compiler

A native page compiler treats pages, millimeters, typography, vector charts, and conditional blocks as first-class primitives rather than print workarounds bolted onto a screen engine.

const pdf = await fetch("https://api.composa.ai/v1/run", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.COMPOSA_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    template_id: "0536a015-…",
    format: "pdf",
    data: {
      client: "Meridian Labs",
      invoice_no: "INV-0482",
      total: "$12,390.00",
    },
  }),
}).then(async (r) => Buffer.from(await r.arrayBuffer()));

With Composa, one warm call compiles an 8-page private banking review in 0.3 seconds, and POST /v1/run/batches compiles 100 personalized 8-page reports (800 pages) in 18.3 seconds or queues up to 50,000 personalized files with signed HMAC-SHA256 webhooks.

  • Exact determinism: identical JSON produces the exact same file every time, with pinned template versions (30 versions kept) and optional Zero-Retention on Pro and above.
  • Zero browser fleets: no headless Chrome containers, no Chromium upgrades breaking print rules, and no font fallback surprises.
  • Shared team ownership: Engineering owns the JSON schema and API call; Design, Data Science, and Business iterate visually on drafts without redeploying the app.

If your team is still debugging @media print rules or restarting Puppeteer containers on month-end runs, read our full breakdown in Composa vs. Puppeteer & HTML-to-PDF.

Try the native compiler

Ship deterministic PDFs from one JSON call.

100 pages / month free · No card required · Zero watermarks. Full API, 50,000-item batches, and OAuth 2.1 MCP included on every plan.