DEV Community

Mukul Dutt
Mukul Dutt

Posted on • Originally published at propzapi.com

HTML to PDF API: convert HTML to PDF in one call

Originally published on propzapi.com — cross-posted here.

wkhtmltopdf is dead. The repo was archived in 2023, the last release was 2020, and it ships an unpatched critical SSRF (CVE-2022-35583). If your PDF pipeline still runs on it, you're shipping a 2012 browser engine with a security hole. Here's the modern version.

What an HTML to PDF API does

You send HTML (or a stored template id plus data), it renders the page in headless Chromium, and returns a URL to a finished PDF. Chromium prints with the same engine that draws your page in a browser, so your flexbox, grid, and web fonts come out right — no 2012 WebKit fork mangling the layout.

One call

curl https://api.propzapi.com/v1/images \
  -H "X-API-Key: pk_live_…" -H "Content-Type: application/json" \
  -d '{"template":"tpl_…","format":"pdf","data":{"number":"1042","total":"$4,200.00"}}'
# → { "url": "https://images.propzapi.com/img_….pdf", "width":794, "height":1123, "format":"pdf", "bytes":6679 }
Enter fullscreen mode Exit fullscreen mode

Store an invoice or certificate template once with {{variables}}, then render per record. A common wiring: a payment webhook fires, your handler POSTs the template with that order's data, and you email the returned PDF URL. Billed on delivery — a failed render costs nothing.

The gotchas that bite everyone

  • Page size is CSS. A4 is 794×1123px at 96dpi, US Letter is 816×1056. Set margins with the @page rule.
  • Backgrounds get stripped by default — add print-color-adjust: exact or your dark header prints white.
  • Fonts and images: wait for webfonts to load before rendering, and use absolute URLs for anything the PDF shows (the render server has no session to authenticate with).

When not to reach for it

For a 40-page contract with running headers, page numbers, and footnotes, use a paged-media engine like Prince — Chromium's page-break control is uneven. Chromium is built for single-page outputs: invoices, receipts, tickets, certificates, one-page reports.

I wrote the full guide — self-host Puppeteer vs hosted, a comparison table, the WeasyPrint option, and every gotcha with its fix — in the HTML to PDF API guide, built on propzapi.

Top comments (0)