DEV Community

Rahul
Rahul

Posted on • Originally published at invoicepdf-app.azurewebsites.net

Generate invoice PDFs without a headless browser

You probably don't need Chromium to make a PDF

The default advice for "generate a PDF" is HTML-to-PDF via headless Chromium
(Puppeteer/Playwright). For arbitrary web pages, fine. For a document with a
known layout — an invoice, a receipt, a statement — it's the wrong tool:

  • ~300MB of Chromium to ship and keep patched
  • system libraries that break on minimal/serverless images
  • seconds of cold-start on the first request
  • --no-sandbox foot-guns and memory tuning

For structured documents you need correct layout and correct math, not a
browser.

The lighter approach: render straight from data

InvoicePDF takes JSON and returns a PDF — no browser involved:

curl -X POST https://invoicepdf-app.azurewebsites.net/invoice \
  -H "Content-Type: application/json" \
  -d '{"number":"INV-1","currency":"USD","seller_name":"Me LLC",
       "buyer_name":"Acme Corp",
       "items":[{"description":"Consulting","quantity":8,"unit_price":120}],
       "tax_rate_percent":10}' \
  --output invoice.pdf
Enter fullscreen mode Exit fullscreen mode

Under the hood it's fpdf2 — pure Python, no system deps — so it starts
instantly, sips memory, and hosts on a free tier like a static app.

Bonus: get the money math right

Never use floats for money (0.1 + 0.2 != 0.3). Keep amounts as integer minor
units
(cents) and format at the very end, so $27.00 + 10% tax is exactly
$29.70. InvoicePDF does this internally.

Try it

If you've been reaching for headless Chromium to make invoices, this is a much
lighter path. Feedback welcome.

Top comments (0)