What is a PDF generation API?

A PDF generation API is a web service that turns HTML, a URL, or a template combined with JSON data into a downloadable PDF file through a single API call. Instead of building PDF rendering logic yourself, an application sends a request and receives a finished PDF back.

Why it exists

Rendering a pixel-accurate PDF is harder than it looks: fonts need to be embedded, page breaks need to respect content, and CSS layout has to be evaluated by an actual rendering engine, not approximated. A PDF generation API centralizes that work — it runs a rendering engine (commonly a headless browser like Chromium) on the server side, so any application, script, or agent that can make an HTTP request can produce a correctly formatted PDF without embedding a browser or a print pipeline of its own.

This is distinct from a client-side PDF library, which runs inside your own application process and leaves layout, fonts, and pagination as your responsibility. It is also distinct from a desktop “print to PDF” feature, which is manual and not callable by another program. A PDF generation API is built to be called programmatically — from a backend, a no-code automation, or an AI agent — and to return the same output every time for the same input.

How it works

The typical flow is: your application sends a source (HTML, a URL, or a template ID with data) to the API; the service renders that source with a real browser engine; the resulting PDF bytes are returned in the response, or a link to download them. An idempotencyKey is often supported so retried requests do not generate the document twice.

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": "html", "html": "<h1>Invoice #1024</h1>" },
    "options": { "format": "A4", "margin": "20mm" },
    "idempotencyKey": "invoice-1024-attempt-1"
  }' \
  --output invoice.pdf

The same idea works as an MCP tool for AI agents. With Docweave’s open-source MCP server (npx @docweave/mcp), an agent calls a single generate_pdf tool instead of writing HTTP code, and gets a PDF back as part of its tool-call loop.

How Docweave relates to this

Docweave is a PDF generation API: one REST call to POST /api/v1/pdf accepts HTML, a URL, or a template + JSON, renders it with Chromium, and returns a PDF. It is priced per document rather than per page, supports an idempotencyKey so retries never double-bill or double-generate, and ships an open-source MCP server so AI agents can call it as a native tool rather than hand-rolling HTTP requests.

FAQ

What is a PDF generation API?

A PDF generation API is a web service that converts HTML, a URL, or a template plus JSON data into a PDF file through a single API call, rather than requiring a desktop print driver, a browser's built-in print function, or a hand-built PDF library.

How is a PDF generation API different from a PDF library?

A library (like a PDF-writing package for Python or Node) runs inside your own process and you manage layout, fonts, and rendering yourself. An API is a hosted service: you send a request over HTTP and get a finished PDF back, so the rendering engine, fonts, and browser dependencies live on the provider's infrastructure instead of yours.

What can a PDF generation API be used for?

Common uses include invoices and receipts, contracts and signed agreements, reports and dashboards exported for offline sharing, shipping labels, certificates, and AI agents that need to hand a user a downloadable document instead of a wall of chat text.

Do PDF generation APIs charge per page or per document?

It varies by provider — some bill per page or per conversion credit, others per document regardless of length. Check each provider's current pricing page for exact terms; Docweave, for example, bills per document rather than per page.

Try the MCP-native PDF API.

Get an API key