What is an HTML-to-PDF API?
An HTML-to-PDF API is a web service that converts HTML markup or a URL into a PDF file through a single API call, rendering the page in a real browser engine and printing the result to PDF.
The concept, expanded
Before HTML-to-PDF APIs existed, generating a PDF from an application usually meant building the document programmatically — placing text, lines, and boxes at exact coordinates using a PDF library. That works, but it means learning a separate layout model instead of reusing the HTML and CSS a team already knows.
An HTML-to-PDF API flips that around: you write (or already have) a normal web page — HTML for structure, CSS for layout and styling — and send it to the API. The API renders that page the same way a browser would, then converts the rendered result into a PDF. The output looks like the web page did, including fonts, tables, images, and print-specific CSS such as page breaks and margins.
How it works
Most HTML-to-PDF APIs follow the same three steps under the hood:
- Load the source. The API receives raw HTML, a URL to fetch and render, or a stored template combined with JSON data.
- Render in a browser engine. A headless browser (most commonly Chromium) parses the HTML and CSS, lays out the page, applies fonts, and executes any client-side JavaScript, just as it would for a person viewing the page.
- Print to PDF. The browser engine's built-in print-to-PDF capability converts the rendered page into a PDF file, honoring page size, margins, and page-break CSS rules, and the API returns that file to the caller.
A minimal request looks like this:
POST /api/v1/pdf
Authorization: Bearer dw_live_your_key
Content-Type: application/json
{
"source": { "type": "html", "html": "<h1>Invoice #1024</h1>" },
"options": { "format": "A4", "margin": "20mm" }
}Where Docweave fits
Docweave is an HTML-to-PDF API: POST /api/v1/pdf accepts HTML, a URL, or a template + JSON, renders it with Chromium, and returns the PDF. It's billed per document rather than per page, so a long report and a short receipt cost the same to generate, and every request can carry an idempotencyKey so a retry never produces a duplicate document.
Docweave is also MCP-native: the open-source generate_pdf tool (npx @docweave/mcp) lets an MCP client — Claude, Cursor, or another agent — call the same rendering pipeline directly as a tool call, without wiring up HTTP requests by hand.
FAQ
What is an HTML-to-PDF API?
An HTML-to-PDF API is a web service that takes HTML markup, a URL, or a template with data, renders it in a browser engine, and returns a PDF file — typically through a single REST call rather than a desktop print dialog.
How does an HTML-to-PDF API actually generate the PDF?
It loads the HTML (or navigates to the URL) inside a real or headless browser engine such as Chromium, waits for the page to render — including CSS, fonts, and any client-side JavaScript — and then invokes the browser's print-to-PDF capability to produce the file.
Why use an HTML-to-PDF API instead of a PDF library?
Traditional PDF libraries require you to build documents element by element in code. An HTML-to-PDF API lets you design a document with ordinary HTML and CSS — the same skills used to build web pages — and offloads rendering, font handling, and pagination to a browser engine.
What are common use cases for an HTML-to-PDF API?
Invoices and receipts, reports and statements, contracts and agreements, shipping labels, and any document an application needs to generate on demand from dynamic data, often triggered from a backend, a no-code automation tool, or an AI agent.
Try the MCP-native PDF API.
Get an API key