The three ways to create a PDF from a template
To generate a PDF from a template you merge data into a fixed layout and render the result, and there are three ways to do it. A template API stores the layout in a hosted editor and takes your data as JSON. HTML plus a renderer fills an HTML template with a templating engine and converts the page to PDF. A PDF library builds the layout in program code, element by element.
All three produce the same kind of file. They differ in who can change the layout and what you have to run.
| Template API | HTML plus a renderer | PDF library | |
|---|---|---|---|
| Where the layout lives | Hosted editor | An HTML and CSS file in your repository | Program code |
| Who can change it | Anyone with editor access | A developer who knows CSS | A developer |
| What you run | Nothing; one HTTP call | A templating engine and a renderer or headless browser | The library inside your application |
| Named examples | CraftMyPDF, APITemplate.io | Jinja2 with WeasyPrint, Handlebars with Puppeteer | QuestPDF (C#), PDFKit (Node.js), Apache PDFBox (Java) |
| License cost | Subscription after a free tier | Open source | Open source or revenue-based license |
How a template API works, step by step
Using CraftMyPDF's API reference as the example:
- Design the template in the editor and note its template ID.
- Send a POST request to
https://api.craftmypdf.com/v1/createwith your key in theX-API-KEYheader. - Put
template_idanddatain the JSON body. Both are required.datamay be a JSON object or a stringified JSON string. - Choose
export_type:jsonreturns a link to the stored PDF,filereturns the PDF bytes and stores nothing. - Read the
filefield of the response, which holds the PDF URL, andstatus.
The other two routes replace steps 1 and 2 with files and code you maintain. The Python guide shows the template API and the HTML plus renderer route with documented calls, and this site has matching guides for Node.js, Java and C#.
Worked example: 300 invoices a month on each route
Take a business that sends 300 invoices a month from one invoice template.
Template API. CraftMyPDF's Free plan allows 50 PDFs a month, so 300 needs the Lite plan at $29 a month, which covers 1,200 PDFs and 6 templates (read on the pricing page on 3 October 2026). One PDF is one credit regardless of page count, so a three-page invoice costs the same as a one-page one. Usage would be a quarter of the allowance.
HTML plus a renderer. Jinja2 and WeasyPrint are both open source, so the license cost is zero. The cost is the server that runs them and the developer time to build and adjust the CSS.
PDF library. Also no per-document cost. QuestPDF, for example, is free for businesses under $1 million in annual gross revenue according to its quick start page. Every layout change is a code change.
At 300 documents the money is small either way. The real question is whether $29 a month is cheaper than the developer hours spent on layout requests.
Mistakes to avoid when generating PDFs from templates
- Treating the returned link as permanent. With CraftMyPDF's
export_typeset tojson, theexpirationparameter defaults to 5 minutes and can be set from 1 to 10,080 minutes. Download the file or raise the value. - Letting field names drift. The keys in your data must match the template's placeholders exactly. Keep a field map next to the template.
- Changing a live template with no version control. CraftMyPDF's
versionparameter lets a request pin a template version; file-based templates should live in Git. See template versioning. - Sending oversized payloads. The CraftMyPDF reference lists a 4 MB payload limit and a 100 second timeout on its default regional endpoints.
- Testing only one-page documents. A long table can split across pages in ways a one-page test never shows.
When a paid template tool is worth it, and when a library is enough
A paid template API is worth it when people outside the development team need to change documents, when you want Zapier or Make.com to trigger generation, or when you cannot run a renderer on your hosting.
An open source route is enough when one developer owns both the code and the layout, the layout rarely changes, and you already have a server to run it on. In that case paying for a template API buys little. If you are unsure, the method choice guide works through the decision with your own volumes.
Sources used for this page
The facts above come from the pages below, read on 3 October 2026. We have not used these products hands-on. Prices and terms change, so confirm them on the vendor's site before you buy.
- CraftMyPDF API Reference (OpenAPI specification) — Vendor documentation · craftmypdf.com · checked 2026-10-03
- Pricing - CraftMyPDF.com — Vendor pricing page · craftmypdf.com · checked 2026-10-03
- PDF Generation API - CraftMyPDF — Vendor product page · craftmypdf.com · checked 2026-10-03
- Pricing - APITemplate.io — Vendor pricing page · apitemplate.io · checked 2026-10-03
- First Steps - WeasyPrint documentation — Vendor documentation · doc.courtbouillon.org · checked 2026-10-03
- API - Jinja documentation — Vendor documentation · jinja.palletsprojects.com · checked 2026-10-03
- Handlebars API reference: compilation — Vendor documentation · handlebarsjs.com · checked 2026-10-03
- Page.pdf() method | Puppeteer — Vendor documentation · pptr.dev · checked 2026-10-03
- Quick start | QuestPDF — Vendor documentation · questpdf.com · checked 2026-10-03
- PDFKit: a JavaScript PDF generation library — Vendor documentation · pdfkit.org · checked 2026-10-03
- Apache PDFBox: a Java PDF library — Vendor documentation · pdfbox.apache.org · checked 2026-10-03