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 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.pdfSave 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.
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();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.
| Option | Cost | Your effort | Print quality |
|---|---|---|---|
| Puppeteer or Playwright on your servers | Free software, plus servers and memory | High: a browser to run, patch and keep alive | Good HTML support; page headers and long tables need work |
| wkhtmltopdf | Free software | Medium, but the project is no longer maintained | Old WebKit engine: no modern CSS such as grid |
| PDFKit, ReportLab and other drawing libraries | Free software | High: every line placed in code | Exact, but every layout change is a code change |
| A PDF generation API | A monthly plan above the free allowance | Low: one HTTPS request | Chromium 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.
What decides print quality
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:
- Invoice PDF API: line items, tax and totals worked out for you, and long invoices that stay readable.
- Certificate generator: a named certificate for every learner or attendee.
- Report PDF generator: multi-page reports with headers and page numbers.
- Ticket PDF generator: printable event tickets with a tear-off stub.
- Contract PDF generator: your agreement, filled in for every client.
- Or browse all PDF templates, each with its real sample data.
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.
| Plan | PDFs a month | Monthly price | Extra PDFs per 1,000 |
|---|---|---|---|
| Free | 100 | Free | None (hard limit) |
| Starter | 2,500 | $19 | $9.00 |
| Growth | 10,000 | $49 | $6.00 |
| Pro | 50,000 | $129 | $3.50 |
| Scale | 200,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.