Skip to content

PDF generation API

PDF generation API for your apps and AI agents.

Send HTML, or a template ID and JSON data, in one API call and get a finished PDF back: invoices, reports, statements and more. Save reusable templates in the app for documents you generate again and again.

Works from any language that can make an HTTPS request, and from any agent that can call a function. MCP is optional.

Sample invoice PDF: Northwind Studio Ltd billing a Berlin law firm, seven line items and a total due of €5,160.00.

POST /html-to-pdf

{
  "html": "<!doctype html>…",
  "data": { "items": […], … }
}

or POST /templates/{id}/generate

{ "data": { "items": […], … } }

200 OK · application/pdf

How it works

Send HTML or a template. Get a PDF back.

Call the API with your own HTML, or with the ID of a template saved in the app plus JSON data. Either way the response is the finished PDF.

  1. 01

    Create an API key

    Create an account and generate a key under Settings → API keys. Keep it on your server or in your agent's tool executor, never in a browser or a prompt.
  2. 02

    Send HTML, or a template ID and JSON

    POST your HTML to /html-to-pdf, with optional data for placeholders such as {{customer.name}}. Or save the layout as a template in the app, starting from the invoice or report template if you like, and send only its ID and the data.
  3. 03

    Get the PDF back

    The response is the PDF itself, ready to store, email or hand back to a user or an agent. Your code or agent supplies the values; the layout stays the same every time.

One request

HTML or JSON in, a finished PDF out.

Both requests can produce the invoice above from the same HTML and JSON data: send the markup each time, or save it as a template once and send only the data. Totals and tax are calculated by your system; the layout only places them.

Generate from HTML

curl -X POST https://api.sublimepdf.com/v1/html-to-pdf \
  -H "Authorization: Bearer $SUBLIMEPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --rawfile html template.html --slurpfile data data.json \
        '{ html: $html, data: $data[0] }')" \
  --output invoice.pdf

Generate from a saved template

curl -X POST https://api.sublimepdf.com/v1/templates/$SUBLIMEPDF_TEMPLATE_ID/generate \
  -H "Authorization: Bearer $SUBLIMEPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --slurpfile data data.json '{ data: $data[0] }')" \
  --output invoice.pdf

Page size, margins, headers, footers and URL rendering are covered in the HTML to PDF API overview and the API reference.

Placeholders and loops
In saved templates or HTML sent with data: fields, nested objects, repeated line items and optional sections.
Print-grade layout
CSS @page sizes and margins, repeating table headers and page numbers.
Retry-safe requests
Send an Idempotency-Key so a retried request does not create a duplicate.
Plain HTTP
Bearer-token auth over HTTPS. No SDK required.

Download this exact sample

Sample output rendered from this template and data with headless Chromium.

For AI agents

Give your agent a PDF tool, not a layout job.

Agents are good at gathering facts and writing summaries. Give them one tool that sends HTML, or a saved template ID and data, and returns a PDF, so pages, tables and typography are handled for them.

Ordinary tool calling
Describe generate_pdf with JSON Schema. Any framework that supports function calling can use it.
Key stays server-side
Your tool executor holds the API key and calls SublimePDF. The model never sees it.
HTML or a template
Point the agent at a saved template for a fixed layout, or let it send complete HTML when no template fits.
MCP if you want it
Expose the same tool to MCP clients. It is an option, not a requirement.

generate_pdf tool definition

{
  "name": "generate_pdf",
  "description": "Create a PDF with SublimePDF. Pass template_id and data to fill a template saved in the SublimePDF app, or html (a complete HTML document) with optional data. Provide exactly one of template_id or html. Returns a document reference, not the PDF bytes.",
  "parameters": {
    "type": "object",
    "properties": {
      "template_id": { "type": "string", "description": "ID of a saved template. Omit when sending html." },
      "html": { "type": "string", "description": "Complete HTML document. Omit when sending template_id." },
      "data": { "type": "object", "description": "Values for placeholders. Required with template_id." }
    },
    "additionalProperties": false
  }
}

The executor behind this tool calls POST /html-to-pdf or POST /templates/{id}/generate, stores the PDF and returns a short reference to the model instead of raw bytes.

Reusable templates

Start from a working template.

Templates are optional. Save one in the app when you generate the same layout again and again. Each starter ships with its HTML source, sample JSON and the PDF it produces.

All templates

Use cases

Documents your systems already know how to describe.

Invoices from billing data

Map orders or subscription events to one invoice layout, sent as HTML or saved as a template, and generate a PDF per invoice with consistent numbering, currency formatting and pagination.

Invoice PDF API

Reports written by agents

An agent analyses exports or tickets, writes the narrative and figures, and sends them as HTML or as data for your saved report template. People receive a document, not a chat transcript.

Agent report generation

Generate your first PDF with one API call.

Create an account, copy an API key and send HTML, or a template ID with JSON data, from your code or your agent.