Skip to main content

Template Renderer

Render pre-designed templates with dynamic data injection.

Endpoint

POST /api/v1/renderer/templates/:id

Description

The Template Renderer allows you to generate PDFs or images from templates created in the PDFGen Studio editor. Inject dynamic data to populate text fields, tables, images, and more.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the template

Request Body

{
"data": {
"fieldName": "value",
"tableName": [
{ "column1": "row1", "column2": "value1" },
{ "column1": "row2", "column2": "value2" }
]
},
"options": {
"format": "pdf",
"response": "binary"
}
}

Data Object

The data object contains key-value pairs that map to placeholders in your template:

  • Text fields: Use the field name as key
  • Tables: Use the table name as key with an array of row objects
  • Images: Provide a URL or base64 encoded image

Query Parameters

All options can be passed as query parameters:

POST /api/v1/renderer/templates/:id?format=pdf&response=binary&textOverflow=truncate
ParameterTypeDefaultDescription
formatstringpdfOutput format: pdf, png, jpg
responsestringbinaryResponse type: binary, base64
textOverflowstringtruncateText overflow handling: truncate, wrap, scale, none
tablePaginationbooleantrueEnable automatic table pagination
tableHeaderOnNewPagebooleantrueRepeat table headers on new pages
pixelRationumber2Image resolution multiplier (1-4)
qualitynumber0.95Image quality for JPEG (0.1-1)
pageIndexnumber-Render specific page only (0-indexed)

Options Object

Options can also be passed in the request body:

{
"data": { ... },
"options": {
"format": "pdf",
"response": "binary",
"textOverflow": "truncate",
"tablePagination": true,
"tableHeaderOnNewPage": true,
"pixelRatio": 2,
"quality": 0.95,
"pageIndex": 0
}
}
Query Parameters Take Precedence

When the same option is specified in both query params and body options, the query parameter value is used.

Options Reference

format

Output format for the rendered document.

ValueDescription
pdfPDF document (default)
pngPNG image
jpgJPEG image

response

Response encoding type.

ValueDescription
binaryRaw binary data (default)
base64Base64 encoded string

textOverflow

How to handle text that exceeds the text box boundaries.

ValueDescription
truncateCut off text that doesn't fit (default)
wrapWrap text to next line
scaleScale font size down to fit
noneAllow text to overflow

tablePagination

When true, tables that exceed the page height automatically continue on the next page.

tableHeaderOnNewPage

When true, table headers are repeated on each new page when a table spans multiple pages.

pixelRatio

Resolution multiplier for image output (PNG/JPG). Higher values produce higher resolution images.

  • Range: 1 to 4
  • Default: 2

quality

JPEG compression quality. Only applies when format is jpg.

  • Range: 0.1 to 1
  • Default: 0.95

pageIndex

Render only a specific page from a multi-page template. Pages are 0-indexed.

Examples

Basic PDF Generation

curl -X POST "https://api.pdfgenstudio.com/api/v1/renderer/templates/tmpl_abc123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"data": {
"customerName": "John Doe",
"invoiceNumber": "INV-2024-001",
"date": "January 4, 2026"
}
}' \
--output invoice.pdf

High-Resolution PNG with Query Params

curl -X POST "https://api.pdfgenstudio.com/api/v1/renderer/templates/tmpl_abc123?format=png&pixelRatio=3" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"data": {"title": "My Document"}}' \
--output document.png

Base64 Response

curl -X POST "https://api.pdfgenstudio.com/api/v1/renderer/templates/tmpl_abc123?response=base64" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"data": {"name": "Test"}}'

Response:

{
"data": "JVBERi0xLjcKCjEgMCBvYmoKPDwKL1R5cGUgL0NhdGFsb2cK...",
"contentType": "application/pdf"
}

Table Data Injection

curl -X POST "https://api.pdfgenstudio.com/api/v1/renderer/templates/tmpl_abc123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"data": {
"invoiceNumber": "INV-001",
"items": [
{ "product": "Widget A", "qty": 2, "price": 29.99 },
{ "product": "Widget B", "qty": 1, "price": 49.99 },
{ "product": "Widget C", "qty": 5, "price": 9.99 }
],
"total": 159.92
},
"options": {
"tablePagination": true,
"tableHeaderOnNewPage": true
}
}' \
--output invoice.pdf

Response

Success (Binary)

  • Status: 200 OK
  • Content-Type: application/pdf, image/png, or image/jpeg
  • Body: Raw binary data

Success (Base64)

{
"data": "<base64-encoded-content>",
"contentType": "application/pdf"
}

Error Response

{
"error": "Not Found",
"message": "Template not found",
"statusCode": 404
}