Practical guide

Generate PDF from template: the three routes and how to choose between them

Last reviewed October 10, 2026

Quick answerThree routes: a template API (design in an editor, send JSON), HTML plus a renderer (fill an HTML template, convert it), or a PDF library (draw the layout in code). Choose by who edits the layout.

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, and a PDF library compared
Template APIHTML plus a rendererPDF library
Where the layout livesHosted editorAn HTML and CSS file in your repositoryProgram code
Who can change itAnyone with editor accessA developer who knows CSSA developer
What you runNothing; one HTTP callA templating engine and a renderer or headless browserThe library inside your application
Named examplesCraftMyPDF, APITemplate.ioJinja2 with WeasyPrint, Handlebars with PuppeteerQuestPDF (C#), PDFKit (Node.js), Apache PDFBox (Java)
License costSubscription after a free tierOpen sourceOpen source or revenue-based license

We may earn a commission if you buy through links on this page, at no extra cost to you.

Start free with CraftMyPDF →

How a template API works, step by step

Using CraftMyPDF's API reference as the example:

  1. Design the template in the editor and note its template ID.
  2. Send a POST request to https://api.craftmypdf.com/v1/create with your key in the X-API-KEY header.
  3. Put template_id and data in the JSON body. Both are required. data may be a JSON object or a stringified JSON string.
  4. Choose export_type: json returns a link to the stored PDF, file returns the PDF bytes and stores nothing.
  5. Read the file field of the response, which holds the PDF URL, and status.

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 and Java.

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, billed monthly, which covers 1,200 PDFs and 6 templates (read on the pricing page on October 10, 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, while publicly traded companies and public-sector entities need a paid license whatever their revenue. 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_type set to json, the expiration parameter 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 list of the field names next to the template; how JSON data reaches a template explains the matching.
  • Changing a live template with no version control. CraftMyPDF's version parameter 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.

Sources used for this page

The facts above come from the pages below, read on October 3, 2026; pricing was read again on October 10, 2026. Prices and terms change, so confirm them on the vendor's site before you buy.

  1. CraftMyPDF API Reference (OpenAPI specification) — Vendor documentation · craftmypdf.com · read October 3, 2026
  2. Pricing - CraftMyPDF.com — Vendor pricing page · craftmypdf.com · read October 10, 2026
  3. PDF Generation API - CraftMyPDF — Vendor product page · craftmypdf.com · read October 3, 2026
  4. Pricing - APITemplate.io — Vendor pricing page · apitemplate.io · read October 10, 2026
  5. First Steps - WeasyPrint documentation — Vendor documentation · doc.courtbouillon.org · read October 3, 2026
  6. API - Jinja documentation — Vendor documentation · jinja.palletsprojects.com · read October 3, 2026
  7. Handlebars API reference: compilation — Vendor documentation · handlebarsjs.com · read October 3, 2026
  8. Page.pdf() method | Puppeteer — Vendor documentation · pptr.dev · read October 3, 2026
  9. Quick start | QuestPDF — Vendor documentation · questpdf.com · read October 3, 2026
  10. PDFKit: a JavaScript PDF generation library — Vendor documentation · pdfkit.org · read October 3, 2026
  11. Apache PDFBox: a Java PDF library — Vendor documentation · pdfbox.apache.org · read October 3, 2026