PDF from Template
Generate a PDF document from a Liquid template with variable substitution
/v1/pdf/from-template
curl -X POST "https://pdf.toolkitapi.io/v1/pdf/from-template" \
-H "Content-Type: application/json" \
-d '{
"template": "<h1>Invoice #{{ invoice_number }}</h1><p>Date: {{ date }}</p><table><tr><th>Item</th><th>Amount</th></tr>{% for item in items %}<tr><td>{{ item.name }}</td><td>{{ item.price }}</td></tr>{% endfor %}</table><p><strong>Total: {{ total }}</strong></p>",
"variables": {
"invoice_number": "INV-2024-0042",
"date": "December 15, 2024",
"items": [
{"name": "Consulting", "price": "$2,500"},
{"name": "Development", "price": "$5,000"}
],
"total": "$7,500"
},
"page_size": "A4"
}'
import httpx
resp = httpx.post(
"https://pdf.toolkitapi.io/v1/pdf/from-template",
json={
"template": "<h1>Invoice #{{ invoice_number }}</h1><p>Date: {{ date }}</p><table><tr><th>Item</th><th>Amount</th></tr>{% for item in items %}<tr><td>{{ item.name }}</td><td>{{ item.price }}</td></tr>{% endfor %}</table><p><strong>Total: {{ total }}</strong></p>",
"variables": {
"invoice_number": "INV-2024-0042",
"date": "December 15, 2024",
"items": [
{"name": "Consulting", "price": "$2,500"},
{"name": "Development", "price": "$5,000"}
],
"total": "$7,500"
},
"page_size": "A4"
},
)
print(resp.json())
const resp = await fetch("https://pdf.toolkitapi.io/v1/pdf/from-template", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"template": "<h1>Invoice #{{ invoice_number }}</h1><p>Date: {{ date }}</p><table><tr><th>Item</th><th>Amount</th></tr>{% for item in items %}<tr><td>{{ item.name }}</td><td>{{ item.price }}</td></tr>{% endfor %}</table><p><strong>Total: {{ total }}</strong></p>",
"variables": {
"invoice_number": "INV-2024-0042",
"date": "December 15, 2024",
"items": [
{"name": "Consulting", "price": "$2,500"},
{"name": "Development", "price": "$5,000"}
],
"total": "$7,500"
},
"page_size": "A4"
}),
});
const data = await resp.json();
console.log(data);
# See curl example
{
"pdf": "JVBERi0xLjcKMSAwIG9iago8...",
"page_count": 1,
"file_size": 45320,
"rendered_html_length": 412
}
Try It Live
Description
How to Use
1. Provide your template via `template` (inline HTML+Liquid string) or `template_url` (public HTTPS URL).
2. Pass `variables` as a JSON object — these become available in the template as Liquid variables.
3. Optionally set `page_size` (`A4`, `A3`, `A5`, `Letter`, `Legal`) and `strict` mode (errors on undefined variables).
4. The response contains the generated PDF as base64, with page count and file size.
About This Tool
PDF from Template generates PDF documents by rendering a Liquid template (Shopify-compatible syntax) with your data, converting the resulting HTML to a polished PDF. This lets you create invoices, reports, certificates, letters, and any structured document from reusable templates.
Liquid templates support variables (`{{ name }}`), loops (`{% for item in items %}`), conditionals (`{% if paid %}`), and filters (`{{ name | upcase }}`). Write your template as HTML with Liquid tags, pass your data as variables, and get back a print-ready PDF.
Templates can be provided inline or fetched from a public HTTPS URL, making it easy to manage templates externally and update them without changing your code.
Why Use This Tool
- Invoice generation — Create invoices from a template with dynamic line items and totals
- Certificate creation — Generate personalized certificates with recipient names and dates
- Report building — Produce data-driven reports by looping through datasets in the template
- Letter automation — Generate form letters with personalized greetings and content
- Contract generation — Fill contract templates with party names, dates, and terms
Frequently Asked Questions
What Liquid features are supported?
Can I include CSS styling?
What happens with undefined variables?
Start using PDF from Template now
Get your free API key and make your first request in under a minute.