PDF generation · Implement
How to Generate a PDF from JSON Data
Design a template, bind a JSON contract, validate the payload, and generate a PDF through a server-side API request.
For developer · 7 min · Reviewed Jul 31, 2026
Define a stable document contract
Start from the document, not the database. Decide which fields the template needs and map application models into a stable JSON object.
Keep calculations in application code. Send final display values such as totals, tax, dates, and localized currency to the template.
{
"data": {
"invoiceNumber": "INV-1042",
"customer": { "name": "Example BV" },
"items": [
{ "description": "Platform subscription", "quantity": 1, "price": 29 }
],
"total": 29
}
}Bind and preview the template
Define the same structure in the visual designer. Bind text fields directly and bind a repeated table row to the items array.
Preview with small and large item arrays before promoting the design.
Validate before rendering
Call the validation endpoint in integration tests or before expensive workflows. A validation failure is deterministic and should be fixed rather than retried unchanged.
Generate on the server
Use the bearer token from trusted backend code and handle the response as binary PDF data.
curl -X POST "https://pdfdesignapi.com/api/v1/generate/single/TEMPLATE_UUID" \
-H "Authorization: Bearer API_TOKEN" \
-H "Content-Type: application/json" \
-d @payload.json \
--output document.pdfMove to production deliberately
Render against a staging template with fixtures, review the output, then promote the immutable version to production. Use asynchronous jobs for heavier documents and batch generation for larger runs.