HTML to PDF API: The Complete Guide for Developers
Converting HTML to PDF is one of those tasks that sounds simple until you actually try it. You spin up Puppeteer, wrestle with headless Chrome flags, debug font rendering issues, and an hour later you're questioning your career choices.
There's a better way: use a dedicated HTML to PDF API. Send your HTML in, get a PDF back. No browser infrastructure to maintain.
Why use an API instead of self-hosting?
- No infrastructure — headless Chrome eats RAM. A single instance uses 200-500 MB. Scale that to concurrent requests and you're running a browser farm.
- No dependency hell — Puppeteer/Playwright versions, Chromium binaries, system fonts, missing libs on Alpine Linux... an API removes all of this.
- Consistent output — same rendering engine, same fonts, same result every time. No "works on my machine" for PDFs.
How it works with Screenshot API
One POST request. That's it.
curl -X POST https://screenshotapis.org/v1/pdf \
-H "X-Api-Key: sk_live_your_key" \
-H "Content-Type: application/json" \
-d '{"html": "<h1>Invoice #42</h1><p>Amount: $99</p>", "format": "A4"}'\
--output invoice.pdf
You can also render a live URL:
curl -X POST https://screenshotapis.org/v1/pdf \
-H "X-Api-Key: sk_live_your_key" \
-d '{"url": "https://your-app.com/invoice/42", "format": "A4"}' \
--output invoice.pdf
Supported options
- Page formats — A4, Letter, Legal, A3, Tabloid
- Orientation — portrait or landscape
- Margins — custom top, right, bottom, left margins
- Headers & footers — inject HTML headers and footers with page numbers
- Print background — include CSS backgrounds and colors
Common use cases
PDF invoices
Render your invoice HTML template server-side, POST it to the API, attach the PDF to an email. No browser needed on your server.
Report generation
Build a dashboard page with charts and tables, render it to PDF for weekly email digests. Works with any charting library that renders in a browser.
Contracts and documents
Generate branded documents from HTML templates. Consistent rendering across all platforms.
Start converting HTML to PDF in 2 minutes
Get your API key — free