What is a programmatic PDF generation?
Programmatic PDF generation is the process of creating PDF documents through code rather than manual export — a script, API call, or AI agent supplies a source (HTML, a URL, or a template + data), and a PDF file is produced automatically, with no person opening a "Print" or "Export" dialog.
Expanding the concept
Most documents — invoices, receipts, reports, contracts, shipping labels — used to be produced by a human filling out a template and manually saving it as a PDF. Programmatic PDF generation removes that manual step. Instead, a piece of software (a backend service, a serverless function, a workflow automation tool, or an AI agent) sends a request that specifies what the document should contain, and a rendering engine turns that request into a finished, downloadable PDF file. The same request format, run a thousand times, produces a thousand consistently formatted documents with zero human involvement per document.
This is what makes it useful at scale: a SaaS product generating an invoice PDF every time a subscription renews, a logistics system stamping out shipping labels, or an AI agent drafting and exporting a report as part of a longer task — all of these are programmatic PDF generation, because the trigger and the formatting logic live in code, not in a person's hands.
How it works
A typical programmatic PDF generation flow has three parts:
- A source. Usually one of: raw HTML/CSS, a public URL to render as-is, or a saved template combined with JSON data to fill it in.
- A rendering engine. Something has to lay out that source and paint it to a page — commonly a headless browser (Chromium) that runs HTML/CSS the same way a normal browser would, then prints it to PDF.
- A trigger. The code path that decides when to generate: an API request, a webhook, a scheduled job, or a tool call from an AI agent.
Here is what that looks like as a single API call:
curl https://docweave.dev/api/v1/pdf \
-H "Authorization: Bearer dw_live_your_key" \
-H "Content-Type: application/json" \
-H "Accept: application/pdf" \
-d '{
"source": { "type": "template", "templateId": "invoice-v2", "data": { "customer": "Acme Co", "total": "$1,204.00" } },
"options": { "format": "A4" }
}' \
--output invoice.pdfHow Docweave relates to this
Docweave is a programmatic PDF generation API built specifically for this pattern. One REST call — POST /api/v1/pdf — accepts HTML, a URL, or a template + JSON as the source, renders it with Chromium, and returns a PDF. It is billed per document rather than per page, and every request can carry an idempotencyKey so retries never generate the same document twice — a common failure mode in automated, programmatic pipelines. For AI agents specifically, Docweave ships an open-source, MCP-native generate_pdf tool (npx @docweave/mcp) so an agent can generate a PDF as a direct tool call instead of hand-rolling HTTP requests.
FAQ
What is programmatic PDF generation?
Programmatic PDF generation is the practice of creating PDF files through code — an API call, script, or automation — instead of a person manually exporting or printing a document. A source (HTML, a URL, or a template plus data) goes in, and a finished PDF comes out, with no human clicking "Print to PDF."
How is programmatic PDF generation different from just exporting a PDF from Word or Google Docs?
Exporting from Word or Docs is a manual, one-off action performed by a human in a GUI. Programmatic generation is triggered by code — on a schedule, in response to an event like a purchase, or by an AI agent — and can produce thousands of documents unattended with consistent formatting each time.
What can trigger programmatic PDF generation?
Common triggers include a REST API call from a backend service, a webhook (like a completed order or a signed contract), a cron job generating recurring reports, or an AI agent calling a tool such as an MCP generate_pdf function during a conversation or workflow.
Is programmatic PDF generation the same as HTML-to-PDF conversion?
HTML-to-PDF conversion is one common technique used inside programmatic PDF generation — a headless browser like Chromium renders HTML/CSS into a PDF. But programmatic PDF generation is the broader concept, and can also start from a plain URL or a saved template bound to JSON data rather than raw HTML.
Try the MCP-native PDF API.
Get an API key