How to Generate PDF From Json

Generating PDFs from structured JSON data is the backbone of automated document workflows — invoices from order data, reports from analytics payloads, certificates from user records. SublimePDF's API accepts a JSON payload paired with an HTML/CSS template and renders a pixel-perfect PDF, letting you generate thousands of documents programmatically without any manual formatting.

Follow the step-by-step instructions below, then use the free tool directly — no registration or download required.

Open Tool →

How to Generate PDF From Json — Step by Step

1

Design your HTML/CSS template

Create an HTML template with placeholder variables using double-curly-brace syntax: {{ customerName }}, {{ invoice.total }}, {{ items }}. Use standard CSS for layout, fonts, and colors — SublimePDF renders with Chromium so all modern CSS works.

2

Structure your JSON payload

Build a JSON object that matches your template variables. Nested objects are accessed with dot notation ({{ address.city }}), and arrays can be iterated with {{#each items}}...{{/each}} blocks.

3

POST to the render endpoint

Send a POST request to /api/v1/render with { "template": "<html>...</html>", "data": { ... }, "options": { "pageSize": "A4" } }. Alternatively, reference a saved template ID with "templateId" instead of inline HTML.

4

Handle array data with loops

Use {{#each lineItems}} to iterate over arrays in your JSON. Inside the loop, {{ this.description }}, {{ this.quantity }}, and {{ this.price }} reference each item's properties. Use {{@index}} for row numbering.

5

Add conditional logic

Use {{#if isPaid}}Paid{{else}}Unpaid{{/if}} to conditionally show content based on boolean or truthy values in your JSON data. This is useful for status badges, discount sections, or optional fields.

6

Retrieve the PDF

The API returns the rendered PDF as binary data. Set "output": "url" to receive a temporary download URL instead, which is useful for sending download links to end users.

Pro Tips

  • 💡 Store your HTML templates on SublimePDF using the Template API (POST /api/v1/templates) and reference them by ID — this avoids sending large HTML strings with every render request.
  • 💡 Use CSS @page rules to set margins, headers, and footers so they don't need to be part of your JSON data structure.
  • 💡 For currency values, format numbers in your application code before passing them as JSON — Handlebars doesn't have built-in number formatting, but you can register custom helpers via the 'helpers' parameter.
  • 💡 Test your template with sample JSON data using the SublimePDF dashboard's live preview before integrating with your application code.

Privacy & Security

All processing happens directly in your browser. Your files are never uploaded to any server — they remain on your device throughout the entire process. SublimePDF uses WebAssembly technology for fast, secure, client-side processing.

Works Everywhere

This tool works on any modern browser — Chrome, Firefox, Safari, or Edge — on desktop, tablet, or mobile. No software to install. PDF is an open ISO standard supported by all major platforms.

How to Generate PDF From Json — FAQ

What templating language does SublimePDF use?
SublimePDF uses Handlebars for template rendering. This gives you variables ({{ name }}), loops ({{#each}}), conditionals ({{#if}}), partials, and custom helpers — enough logic for most document generation needs without a full programming language.
Can I generate multiple PDFs from an array of JSON objects?
Yes. Use the batch endpoint POST /api/v1/render/batch with an array of data objects. Each object is rendered against the same template, producing one PDF per item. Results are returned as a ZIP archive.
How do I include images from my JSON data?
Pass image URLs in your JSON and use them in <img> tags: <img src="{{ companyLogo }}">. The renderer fetches and embeds the images. Base64 data URIs are also supported for inline images.
What happens if a JSON field is missing?
Missing variables render as empty strings by default. Use {{#if fieldName}} guards in your template to handle optional fields gracefully, or set "strictMode": true to receive an error when required fields are missing.

Ready to get started?

Use SublimePDF's free tools right now.

Open Tool