Skip to content
CastPDF

Generate PDFs from your data, without running a browser

A PDF generation API turns your data into finished documents with one HTTPS request. You send HTML, or the ID of a saved template plus JSON, and get a print-ready PDF back in about a second. CastPDF runs the browser, handles page breaks and page numbers, and charges per document, never per page.

  • Updated October 2026
  • 100 free PDFs a month

What a PDF generation API does

Most businesses send the same documents again and again: invoices, receipts, certificates, reports, tickets and contracts. The layout stays the same and only the details change. A PDF generation API keeps the layout as a template and fills in the details each time your app asks.

Template + data = PDF. You design the document once in HTML and CSS, the same code as a web page. Each request sends the parts that change, such as a customer name, a list of items or a course title. The API fills the template, lays the content out on pages and returns a PDF file or a private download link.

That means no PDF library to learn, no headless browser on your servers and no layout code in your app. Your app deals with data. The API deals with paper.

Two ways to make a PDF

Send HTML. Good for one-off documents, or when your app already builds the HTML. Add a data object and the HTML is treated as a template first. The HTML to PDF API page goes deeper on this route.

curl: HTML in, PDF out
curl https://api.castpdf.com/v1/pdf \
  -H "Authorization: Bearer $CASTPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Hello {{ name }}</h1>", "data": {"name": "Ada"}}' \
  --output hello.pdf

Save a template, send JSON. Good for documents you make every day. The design lives in CastPDF with a live preview and version history, so a designer can change it without a deploy. Your code only sends the template ID and the data.

Node.js 20+: template ID and JSON
const res = await fetch('https://api.castpdf.com/v1/pdf', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.CASTPDF_API_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    template_id: process.env.INVOICE_TEMPLATE_ID,
    data: { customer: { name: 'Northwind Traders' }, items: [{ description: 'Design sprint', quantity: 3, unit_price: 950 }] },
    response: 'url',
  }),
});
const { url } = await res.json();
Python: the same request
import os
import requests

res = requests.post(
    "https://api.castpdf.com/v1/pdf",
    headers={"Authorization": f"Bearer {os.environ['CASTPDF_API_KEY']}"},
    json={
        "template_id": os.environ["INVOICE_TEMPLATE_ID"],
        "data": {"customer": {"name": "Northwind Traders"}},
        "response": "url",
    },
    timeout=60,
)
res.raise_for_status()
print(res.json()["url"])

Both routes use one endpoint, POST /v1/pdf. The quickstart takes about five minutes, and the generate a PDF from JSON guide explains the template route step by step.

Build it yourself, or call an API?

You can make PDFs without any API. Many teams start that way, and some should stay there. Here is how the common options compare.

Ways to generate PDFs
OptionCostYour effortPrint quality
Puppeteer or Playwright on your serversFree software, plus servers and memoryHigh: a browser to run, patch and keep aliveGood HTML support; page headers and long tables need work
wkhtmltopdfFree softwareMedium, but the project is no longer maintainedOld WebKit engine: no modern CSS such as grid
PDFKit, ReportLab and other drawing librariesFree softwareHigh: every line placed in codeExact, but every layout change is a code change
A PDF generation APIA monthly plan above the free allowanceLow: one HTTPS requestChromium with print features such as repeating headers

When not to use an API. If you make millions of simple PDFs a night, run your own engine: at that volume a server you control is cheaper. If your documents must never leave your network, self-host. Everyone else usually saves weeks. Developers on Hacker News describe days lost to memory leaks, blank pages and missing fonts when they run Chrome themselves. An API turns that into one request. Our CastPDF vs Puppeteer page goes through the trade-off honestly.

A PDF that looks right on page one can still fall apart on page two. These are the details that separate a usable document from a support ticket.

  • Page breaks that just work. Table rows stay whole, and a totals block stays on one page. See page breaks in HTML to PDF.
  • Repeating table headers. When an invoice runs onto page two, the column names come with it. See repeat table headers.
  • Page numbers. "Page 2 of 5" in the footer, and not on the cover. See page numbers in HTML to PDF.
  • Fonts that load. The font in your preview is the font in the PDF, with Noto installed for many scripts. See fonts in HTML to PDF.
  • No silent loss. If content would be cut off, the request fails with a clear error instead of returning a broken PDF.

Templates render in print mode by default. That mode lays out pages with Paged.js before Chromium prints them, which is how running headers and page counters work.

Documents people generate

Every document type has its own rules. Invoices need correct totals and tax. Certificates need one file per person. Reports need tables that run over many pages. Start with the guide closest to yours:

Connect it from your stack

Any language that can send an HTTPS request can call the API. There is nothing to install. Each developer page has working code and a production checklist: Node.js, Python, PHP, Next.js, Laravel and more on the developers page.

Using a no-code tool? Several of them have a generic HTTP step that can call CastPDF today, for example in an n8n workflow. Ready-made apps for these tools are not available yet.

Pricing per PDF, never per page

One finished document counts as one PDF, whether it has 1 page or 50. Test PDFs are free and unlimited on every plan, and failed requests never count.

CastPDF plans
PlanPDFs a monthMonthly priceExtra PDFs per 1,000
Free100FreeNone (hard limit)
Starter2,500$19$9.00
Growth10,000$49$6.00
Pro50,000$129$3.50
Scale200,000$299$1.75

Paying yearly brings Starter to $15 a month. On paid plans, unused PDFs roll over for one month, and you can go past your plan up to a spending cap you set. We email you at 80% and 100% of your PDFs, so a busy month is never a surprise. The pricing page has the details.

Data, privacy and EU hosting

Your PDFs are made and stored on servers in Germany. A Data Processing Agreement is part of our terms, so there is nothing extra to sign. Stored PDFs are deleted when your plan’s storage time ends, from 1 day on Free to 90 days on Scale.

The renderer only loads images and fonts from public internet addresses, never from private networks, and each document has its own limits: 30 seconds and 50 pages. We do not use your documents to train models.

How CastPDF compares

There are good PDF APIs, and the right one depends on your volume and who edits the templates. At 10,000 PDFs a month CastPDF costs $49, and 50,000 cost $129. Our comparisons use public prices with a source for every fact: start with the best PDF generation APIs, or see CastPDF vs PDFMonkey and CastPDF vs APITemplate.

Go deeper

Everything about the pdf generation api

Every guide, template and example that builds on this page. Each one answers a narrower question in more depth.

Use cases

Templates

Guides

Your language or framework

Comparisons

FAQ

Common questions

What is a PDF generation API?

A service that turns your data into PDF documents over HTTPS. You send HTML, or a template ID and JSON, and get a finished PDF back. It saves you from running a headless browser or writing layout code yourself.

How do I generate a PDF from JSON?

Save a template with fill-in fields such as {{ customer.name }}, then send its ID and your JSON in one request to POST /v1/pdf. CastPDF fills the fields, lays out the pages and returns the PDF.

Is there a free PDF generation API?

CastPDF’s Free plan includes 100 live PDFs a month and unlimited watermarked test PDFs, with no card needed. Live PDFs on the Free plan carry a small Made with CastPDF line; paid plans do not.

How fast is it?

Most documents come back in about a second. Long documents with many images take longer, up to the 30-second limit per document. The request returns when the PDF is ready, so there is nothing to poll.

Do I need to know HTML to use it?

Not to start. Pick a starter template, change the details in the simple form in the dashboard and press Generate PDF. Changing the design itself means editing HTML and CSS, with a live preview as you type.

Can I use my own fonts and logo?

Yes. Load fonts from a public URL or a font service, or embed them, and add your logo as an image. Noto, Liberation and DejaVu fonts are installed and need no loading at all.

What happens if I go over my plan?

On the Free plan, live PDFs pause until next month and test PDFs keep working. On paid plans, extra PDFs continue at your plan’s price per 1,000 until the spending cap you set. We email you at 80% and 100% of your PDFs, and again when you reach the cap.

Where are my PDFs processed?

On CastPDF’s servers in Germany, in the EU. Stored PDFs are kept only for your plan’s storage time, and a Data Processing Agreement is part of the terms.

Make your first PDF in 5 minutes

Pick a template, add your details and download your PDF. You get 100 free PDFs every month, and you don’t need a card.