Skip to main content

PDF Templates

Create reusable HTML/CSS templates with Handlebars and generate PDFs from JSON data. Learn how to preview, publish, and use your templates.

What Are PDF Templates?​

PDFBolt templates are reusable HTML/CSS layouts with Handlebars placeholders. Templates separate the document design from the data, so you can reuse the same layout to generate PDFs with different data.

Use templates for invoices, reports, certificates, and other documents that share the same layout.

  • Template layout: Define the HTML/CSS layout and add Handlebars placeholders for dynamic values, such as {{customer_name}}.
  • Document data: Provide a JSON object with the values for each document. PDFBolt fills the placeholders with your data and generates the PDF.
Template Data Privacy

PDFBolt always redacts templateData from stored conversion request logs after processing. See Data Handling for details.

Your data remains private and secure.

Handlebars

PDFBolt uses Handlebars as its template engine. It adds dynamic values and logic to HTML:

  • Variables: {{customer_name}} inserts the value of customer_name.
  • Conditions: {{#if is_paid}}...{{/if}} displays content when the condition is true.
  • Loops: {{#each items}}...{{/each}} repeats content for each item in an array.
  • Nested objects: {{customer.address.city}} accesses a value in a nested object.
Handlebars Syntax

See the official Handlebars guide for more syntax and examples.

Choose How to Create a Template​

You can create a template with the Dashboard Template Designer, MCP, AI Template Generation, or the Template API. Each option creates a draft that you can review and publish.

Creation pathHow it worksBest for
Dashboard Template DesignerStart from scratch or a gallery template. Edit HTML, sample data, and PDF options, then preview the result.Customizing existing designs or building templates manually.
MCPCreate and manage templates through PDFBolt’s MCP tools.Working with templates through an AI assistant.
AI Template GenerationGenerate a draft from a description and optional reference files, then review it in the Template Designer.Quickly creating a first draft without writing HTML.
Template APICreate, validate, preview, and publish templates through REST endpoints using a Personal Access Token.Application integrations, automated workflows, and AI agents.

How Templates Work​

Templates follow this workflow:

Create a draft → Validate and preview → Publish → Generate PDFs
  1. Create a draft: Prepare the HTML with Handlebars placeholders, sample data, and PDF options.
  2. Validate and preview: Check the template syntax and preview the PDF to verify its content and layout.
  3. Publish: Make the template available for PDF generation.
  4. Generate PDFs: Send templateId and templateData to /v1/direct, /v1/sync, or /v1/async.

To update a published template, save your changes as a new draft. PDF generation continues to use the current published version until you publish the changes.

Simple Example: From Template to PDF​

This example shows how JSON data populates Handlebars variables to produce a PDF. For a detailed walkthrough, see Template Workflow in Detail.

Calculate totals in your application and pass them as template data.

Template HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Invoice #{{invoice_number}}</title>
<style>
.invoice { margin: 40px; }
.status.paid { color: green; }
.status.pending { color: orange; }
</style>
</head>
<body>
<div class="invoice">
<h1>Invoice #{{invoice_number}}</h1>
<p>Dear {{customer.name}},</p>
<div class="items">
{{#each items}}
<p class="item">
{{name}}: ${{price}}
</p>
{{/each}}
</div>
{{#if is_paid}}
<p class="status paid">PAID</p>
{{else}}
<p class="status pending">PENDING</p>
{{/if}}
<p><strong>Total: ${{total}}</strong></p>
</div>
</body>
</html>

Template Data:

{
"invoice_number": "INV-001",
"customer": {"name": "John Doe"},
"items": [
{"name": "Premium Service", "price": "199.99"},
{"name": "Setup Fee", "price": "99.99"}
],
"is_paid": true,
"total": "299.98"
}

Generated PDF:

Generated PDF Invoice

Template Workflow in Detail​

The steps below show how to create and use a template in the Dashboard. You can also manage templates through the Template API or MCP.

1. Create a Template​

  • Open Templates in the Dashboard and start from scratch or a gallery template. You can also generate a draft with AI.
  • Edit the HTML, add Handlebars placeholders, and provide sample data to test them.
  • Set the page format and orientation. Configure headers, footers, and waitForFunction if needed.
  • Use Quick HTML Preview to check changes as you edit. Generate a Real PDF Preview to check page breaks, fonts, and print styles.
  • Save your draft manually or enable auto-save.
Template Designer - Code Editor with Live Preview

For detailed instructions, see the Template Designer guide.

2. Publish the Template​

  • Publish the draft to make that version available to the Conversion API.
  • Copy its unique template ID and include it in Conversion API requests.
  • Use built-in version history to compare changes or restore a previous version.
Template Designer - Publish Version Dialog

3. Generate a PDF​

Before making a request, make sure your template is published and you have a conversion API key. See Conversion API requirements for request details.

  • In the Template Designer, click Get API Code to copy an integration snippet for the current template.
  • Use an official Node.js, Python, or PHP SDK, or call the REST API from any HTTP client.
  • Send the template's templateId and the JSON data for the document as templateData.
  • PDFBolt applies the data to the latest published version and renders the PDF.
Template Designer - API Code Integration Examples
Learn More

Generate PDFs with POST /v1/direct, POST /v1/sync, or POST /v1/async. See the SDK documentation and integration guides for code examples.

4. Receive the Result​

  • Depending on the endpoint, receive the PDF directly, get a download URL (valid for 24 hours for PDFs stored by PDFBolt), or receive a webhook notification when processing is complete.
  • Download the PDF, store it, or send it through your application.
Generated Invoice PDF
Learn More

See Conversion API endpoints for response formats and delivery options.

Before Calling the Conversion API​

When generating a PDF from a template:

  • Authentication: Send your conversion API key in the API-KEY header.
  • Published template: The template must have a published version.
  • Template ID: Use the template’s UUID as templateId. Copy it from the Dashboard or retrieve it through the Template API.
  • Template data: Include templateData as a JSON object, such as {"key": "value"}. Values can include arrays and nested objects.
  • Content source: Provide exactly one of html, url, or templateId.
  • PDF options: If a conversion request includes a PDF parameter that is also saved with the template, the request value takes priority over the saved value for that PDF. The template is not changed.

Complete Invoice Example​

This example includes a complete invoice template, a cURL request with JSON data, and the generated PDF.

Template HTML:

View template HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Invoice - {{invoice_number}}</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Dancing+Script:wght@700&display=swap');

:root {
/* Brand Colors */
--accent-color: #b8577e;

/* Text Colors */
--text-primary: #333;
--text-secondary: #555;
--text-white: #fff;
--text-muted: #777;

/* Background Colors */
--bg-primary: #ffffff;
--bg-secondary: #fafafa;
--bg-accent: #f9f9f9;

/* Border Colors */
--border-light: #e9e9e9;
--border-medium: #ddd;
--border-dark: #ccc;

/* Font Sizes */
--font-size-xs: 12px;
--font-size-sm: 13px;
--font-size-base: 14px;
--font-size-lg: 16px;
--font-size-xl: 18px;
--font-size-2xl: 20px;
--font-size-3xl: 24px;
--font-size-4xl: 54px;
--font-size-5xl: 72px;
}

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
color: var(--text-primary);
font-family: 'Inter', sans-serif;
line-height: 1.7;
font-size: var(--font-size-base);
}

.invoice-container {
background: var(--bg-primary);
padding: 55px;
}

.invoice-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 25px;
gap: 20px;
}

.company-section {
display: flex;
flex-direction: column;
align-items: flex-start;
}

.company-logo {
max-width: 80px;
height: auto;
object-fit: contain;
}

.company-name {
margin-top: 8px;
font-size: var(--font-size-2xl);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 2px;
}

.invoice-title-section {
text-align: right;
}

.invoice-title,
.thank-you-message {
font-family: 'Dancing Script', cursive;
color: var(--accent-color);
font-weight: 700;
line-height: 1;
}

.invoice-title {
font-size: var(--font-size-5xl);
margin-bottom: 10px;
}

.invoice-meta,
.billing-details,
.payment-info-item,
.total-label {
font-size: var(--font-size-base);
color: var(--text-secondary);
}

.invoice-meta-label,
.payment-info-label,
.billing-name,
.total-amount {
font-weight: 600;
color: var(--text-primary);
}

.billing-section,
.summary-section {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
gap: 30px;
flex-wrap: wrap;
}

.billing-block {
padding: 0 8px;
flex: 1;
color: var(--text-secondary);
}

.billing-title,
.payment-info-title {
color: var(--accent-color);
font-size: var(--font-size-lg);
font-weight: 600;
margin-bottom: 8px;
text-transform: uppercase;
letter-spacing: 0.5px;
}

.invoice-meta,
.billing-name,
.payment-info-item {
margin-bottom: 4px;
}

.items-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
color: var(--text-secondary);
}

.table-header {
background: var(--accent-color);
color: var(--text-white);
}

.items-table th {
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}

.items-table th,
.items-table td {
padding: 10px 14px;
font-size: var(--font-size-base);
border-bottom: 1px solid var(--border-medium);
text-align: right;
}

.items-table th:first-child,
.items-table td:first-child {
text-align: left;
}

.payment-info-section {
flex: 1;
margin-top: 12px;
}

.payment-info-section,
.totals-section {
width: 48%;
}

.total-row {
display: flex;
justify-content: space-between;
padding: 10px 4px;
font-size: var(--font-size-base);
align-items: center;
border-bottom: 1px solid var(--border-medium);
}

.total-row-final {
font-weight: 700;
color: var(--accent-color);
border-top: 1.5px solid var(--accent-color);
font-size: var(--font-size-lg);
}

.totals-section .total-row:last-child {
border-bottom: none;
}

.total-row-final .total-amount {
color: var(--accent-color);
}

.thank-you-section {
text-align: center;
margin: 20px 0;
}

.thank-you-message {
font-size: var(--font-size-4xl);
}

@page {
margin: 1.5cm;
}

@media print {
.invoice-container {
padding: 0;
}

.invoice-header,
.billing-section,
.summary-section,
.items-table tr {
page-break-inside: avoid;
}
}
</style>
</head>
<body>
<div class="invoice-container">
<!-- Header section - company logo, name, and invoice details -->
<div class="invoice-header">
<div class="company-section">
{{#if company_logo_url}}
<img src="{{company_logo_url}}" alt="{{company_name}} Logo" class="company-logo"/>
{{/if}}
<div class="company-name">{{company_name}}</div>
</div>
<div class="invoice-title-section">
<h1 class="invoice-title">Invoice</h1>
<div class="invoice-meta">
<p><span class="invoice-meta-label">Invoice No:</span> {{invoice_number}}</p>
<p><span class="invoice-meta-label">Issue Date:</span> {{issue_date}}</p>
{{#if due_date}}
<p><span class="invoice-meta-label">Due Date:</span> {{due_date}}</p>
{{/if}}
</div>
</div>
</div>

<!-- Billing section -->
<div class="billing-section">
<div class="billing-block">
<h2 class="billing-title">Billed from</h2>
<p class="billing-name">{{company_name}}</p>
<div class="billing-details">
{{#if company_address_street}}
<p>{{company_address_street}}</p>
{{/if}} {{#if company_address_line2}}
<p>{{company_address_line2}}</p>
{{/if}}{{#if company_city}}
<p>
{{company_city}}{{#if company_state}}, {{company_state}}{{/if}}{{#if company_postal_code}}
{{company_postal_code}}{{/if}}{{#if company_country}}, {{company_country}}{{/if}}
</p>
{{/if}} {{#if company_email}}
<p>{{company_email}}</p>
{{/if}} {{#if company_phone}}
<p>{{company_phone}}</p>
{{/if}} {{#if company_tax_id}}
<p>Tax ID: {{company_tax_id}}</p>
{{/if}}
</div>
</div>

<div class="billing-block">
<h2 class="billing-title">Billed to</h2>
<p class="billing-name">{{client_name}}</p>
<div class="billing-details">
{{#if client_address_street}}
<p>{{client_address_street}}</p>
{{/if}} {{#if client_address_line2}}
<p>{{client_address_line2}}</p>
{{/if}}{{#if client_city}}
<p>
{{client_city}}{{#if client_state}}, {{client_state}}{{/if}}{{#if client_postal_code}}
{{client_postal_code}}{{/if}}{{#if client_country}}, {{client_country}}{{/if}}
</p>
{{/if}} {{#if client_email}}
<p>{{client_email}}</p>
{{/if}} {{#if client_phone}}
<p>{{client_phone}}</p>
{{/if}} {{#if client_tax_id}}
<p>Tax ID: {{client_tax_id}}</p>
{{/if}}
</div>
</div>
</div>

<!-- Products/services table -->
<table class="items-table">
<thead class="table-header">
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{{#each line_items}}
<tr>
<td class="item-description">{{this.description}}</td>
<td>{{this.quantity}}</td>
<td>{{../currency_symbol}}{{this.unit_price}}</td>
<td>{{../currency_symbol}}{{this.total_amount}}</td>
</tr>
{{/each}}
</tbody>
</table>

<!-- Payment Details -->
<div class="summary-section">
<div class="payment-info-section">
<h3 class="payment-info-title">Payment Information</h3>
{{#if payment_info.bank_name}}
<div class="payment-info-item">
<span class="payment-info-label">Bank Name:</span> {{payment_info.bank_name}}
</div>
{{/if}} {{#if payment_info.account_number}}
<div class="payment-info-item">
<span class="payment-info-label">Account No:</span> {{payment_info.account_number}}
</div>
{{/if}} {{#if payment_info.routing_number}}
<div class="payment-info-item">
<span class="payment-info-label">Routing:</span> {{payment_info.routing_number}}
</div>
{{/if}} {{#if payment_info.payment_terms}}
<div class="payment-info-item">
<span class="payment-info-label">Terms:</span> {{payment_info.payment_terms}}
</div>
{{/if}}
</div>

<!-- Invoice totals and calculations -->
<div class="totals-section">
<div class="total-row">
<span class="total-label">Subtotal</span>
<span class="total-amount">{{currency_symbol}}{{subtotal_amount}}</span>
</div>
{{#if discount_amount}}
<div class="total-row">
<span class="total-label">Discount{{#if discount_percentage}} ({{discount_percentage}}%){{/if}}</span>
<span class="total-amount">-{{currency_symbol}}{{discount_amount}}</span>
</div>
{{/if}} {{#if tax_amount}}
<div class="total-row">
<span class="total-label">Tax{{#if tax_percentage}} ({{tax_percentage}}%){{/if}}</span>
<span class="total-amount">{{currency_symbol}}{{tax_amount}}</span>
</div>
{{/if}}
<div class="total-row total-row-final">
<span class="total-label">Total Amount</span>
<span class="total-amount">{{currency_symbol}}{{total_amount}}</span>
</div>
</div>
</div>

<div class="thank-you-section">
<h3 class="thank-you-message">Thank you!</h3>
</div>
</div>
</body>
</html>

Conversion Request:

Save and publish the template above, then replace YOUR_TEMPLATE_UUID with its template ID and YOUR_API_KEY with your conversion API key.

View cURL request
curl --fail --show-error 'https://api.pdfbolt.com/v1/direct' \
-H 'API-KEY: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"templateId": "YOUR_TEMPLATE_UUID",
"templateData": {
"invoice_number": "INV-2026-014",
"issue_date": "June 13, 2026",
"due_date": "June 27, 2026",
"company_name": "Pink Brand Studio",
"company_email": "[email protected]",
"company_phone": "+1 (555) 222-3344",
"company_address_street": "22 Rose Garden Lane",
"company_city": "Blushville",
"company_state": "CA",
"company_postal_code": "90210",
"company_country": "USA",
"company_tax_id": "PB-2026-001",
"company_logo_url": "https://img.pdfbolt.com/business-logo-template.png",
"client_name": "Luxe Beauty Co.",
"client_email": "[email protected]",
"client_phone": "+1 (555) 667-8899",
"client_address_street": "88 Glamour Ave",
"client_city": "Glowtown",
"client_state": "NY",
"client_postal_code": "10001",
"client_country": "USA",
"client_tax_id": "LB-9988",
"line_items": [
{"description": "Brand Identity Package", "quantity": 1, "unit_price": "600.00", "total_amount": "600.00"},
{"description": "Custom Instagram Templates", "quantity": 1, "unit_price": "200.00", "total_amount": "200.00"},
{"description": "Product Photography Session", "quantity": 1, "unit_price": "350.00", "total_amount": "350.00"},
{"description": "E-commerce Banner Design", "quantity": 2, "unit_price": "75.00", "total_amount": "150.00"},
{"description": "Email Newsletter Template", "quantity": 1, "unit_price": "120.00", "total_amount": "120.00"}
],
"payment_info": {
"bank_name": "Example Bank",
"account_number": "1234567890123456",
"routing_number": "110099001",
"payment_terms": "Due in 14 days"
},
"currency_symbol": "$",
"subtotal_amount": "1420.00",
"discount_percentage": "10",
"discount_amount": "142.00",
"tax_percentage": "20",
"tax_amount": "255.60",
"total_amount": "1533.60"
}
}' \
--output invoice.pdf

Generated PDF:

Generated Invoice PDF

Troubleshooting​

If your request returns an error or the rendered PDF doesn't look right, check these common causes:

ProblemWhat to check
templateId is not a valid UUIDCopy the UUID from the Dashboard or retrieve it through the Template API. Do not use a custom name such as my-template.
Template with ID ... has no active versionPublish the template draft.
'templateData' must also be providedWhen using templateId, include templateData as a JSON object in the same request.
Variables show as blank in the PDFMissing or misspelled variable names can render as blank text without a validation error. Check that the field names in templateData match your Handlebars placeholders, including capitalization.
Images or fonts are missingMake sure asset URLs are accessible to PDFBolt’s renderer. Localhost URLs are not accessible. Use waitForFunction if assets load dynamically.
JavaScript-rendered content is missingUse waitForFunction to wait until dynamic content, such as a chart, has finished rendering.
Header or footer variables are not replacedHandlebars expressions are not evaluated in headers or footers. Use Chromium placeholder classes for values such as page numbers. See headerTemplate and footerTemplate.

For a complete list of API errors and recommended actions, see Error Handling.

Template FAQ​

Do I need coding knowledge to use templates?

Not necessarily. You can:

  • Use AI Template Generation to create a draft from a description or reference files without writing code.
  • Start with a gallery template instead of building a layout from scratch.
  • Handlebars syntax is simple – use {{variable_name}} for data insertion.
How can I test my template before going live?

The Template Designer offers two preview modes:

  • Quick HTML Preview – instant visual feedback as you edit.
  • Real PDF Preview – generates an actual PDF using the same rendering engine as the Conversion API, so you can verify the final output including page breaks, fonts, and print styles.

Your template stays in draft until you publish it, so testing does not affect the current published version. Successful Real PDF Preview renders use your available document conversions.

Can I modify published templates?

Yes. Editing a published template creates a new draft. The published version remains available to the Conversion API until you publish the draft. Use version history to compare changes or restore a previous version as a new draft.

What happens to my template data during PDF generation?

PDFBolt always redacts templateData from stored conversion request logs after processing. Sample data used to preview the template in the Template Designer is saved with the template version. See Data Handling for details.

Can I use custom fonts in my templates?

Yes. Import custom fonts from Google Fonts or another publicly reachable HTTPS stylesheet or font URL. For example, using CSS @import:

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

Or using a <link> tag in your template's <head>:

<link href="https://fonts.googleapis.com/css2?family=Titillium+Web:wght@400;600;700&display=swap" rel="stylesheet" />
Can I pass HTML content in template data?

Yes. By default, Handlebars escapes HTML in variables for security. To render raw HTML from your data, use triple curly braces {{{variable}}} instead of double {{variable}}. For example:

{
"description": "<strong>Bold text</strong> and <em>italic</em>"
}
<!-- Unescaped (renders actual HTML) -->
<p>{{{description}}}</p>

Result in the generated PDF:

Bold text and italic

Use only with trusted data

Triple braces bypass Handlebars escaping. User-generated HTML can change document structure, load resources, or run scripts if your template allows it. Only use {{{variable}}} with content you control or that has been sanitized server-side.

Can I use images in my templates?

Yes. You can include images using:

  • External URLs – reference any publicly accessible image: <img src="https://example.com/logo.png" />
  • Base64 encoding – embed images directly in your template: <img src="data:image/png;base64,..." />
  • Dynamic images – pass image URLs in your template data using Handlebars: <img src="{{company_logo}}" />
  • Inline SVG – embed SVG graphics directly in your HTML for sharp, scalable icons and logos.
How do I control page breaks in templates?

Use CSS print properties to control page breaks:

/* Force a page break before an element */
.new-page { page-break-before: always; }

/* Prevent an element from being split across pages */
.keep-together { break-inside: avoid; }

/* Force a page break after an element */
.section-end { page-break-after: always; }

This is especially useful for long tables or multi-section documents. See our optimizing HTML for PDF guide for more examples.

Can I add headers and footers to template PDFs?

Yes. Enable Display Header & Footer in the template's Options tab. Use Chromium placeholder classes to insert values such as page numbers, dates, and the document title. Handlebars expressions are not evaluated in headers or footers. See headerTemplate and footerTemplate for the full list.

How do I style my templates?

Write your styles directly in the template using one of these approaches:

<style> block in your template's <head>:

<style>
.invoice-title { font-size: 24px; font-weight: bold; color: #333; }
.total { text-align: right; border-top: 2px solid #000; }
</style>

Inline styles directly on HTML elements:

<h1 style="font-size: 24px; font-weight: bold; color: #333;">Invoice</h1>

You can combine both approaches in the same template.

Can I use JavaScript in my templates?

Yes. JavaScript is enabled by default. Use waitUntil: "networkidle" to wait for network activity to settle, or waitForFunction to wait for specific content to finish rendering.

For example, generating a QR code with an external library:

{{#if qr_code_data}}
<canvas id="qr-code"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js"></script>
<script>
new QRious({
element: document.getElementById('qr-code'),
value: {{{json qr_code_data}}}
});
</script>
{{/if}}
Embed JSON in JavaScript

Use the built-in {{{json value}}} helper when embedding templateData into JavaScript. It serializes the value as JSON. Because the output is inserted without HTML escaping, use it only with trusted or sanitized data.

Do you support other templating engines besides Handlebars?

We currently support Handlebars. If you need a different engine, contact us at [email protected] and we'll consider adding it based on user needs.

Additional Resources​

Continue with these guides and API references: