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
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.
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.
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.
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.
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.
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?
Can I generate multiple PDFs from an array of JSON objects?
How do I include images from my JSON data?
What happens if a JSON field is missing?
Related Guides
How to Convert HTML To PDF
Converting HTML to PDF is a core workflow for developers, marketers, and anyone who needs a permanent, printable snapshot of web content. Whether you're archiving a webpage, generating reports from a web app, saving receipts from online purchases, or creating documentation from HTML templates, PDF conversion captures the visual layout, links, and styling in a portable format.
How to Automate PDF Generation
Manually creating PDFs for invoices, reports, or certificates doesn't scale. Automating PDF generation through an API lets your application produce documents on demand — triggered by user actions, scheduled jobs, or webhook events. SublimePDF's REST API integrates into any tech stack (Node.js, Python, Ruby, Go, PHP) and generates PDFs from HTML templates, Markdown, or raw URLs.
How to PDF Webhooks Guide
Webhooks let SublimePDF push notifications to your server when asynchronous events complete — a PDF finishes rendering, a batch job completes, or a conversion fails. Instead of polling the API for status, your application receives an HTTP POST callback the moment results are ready, enabling real-time workflows and reducing unnecessary API calls.