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
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The 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
| Parameter | Type | Default | Description |
|---|---|---|---|
format | string | pdf | Output format: pdf, png, jpg |
response | string | binary | Response type: binary, base64 |
textOverflow | string | truncate | Text overflow handling: truncate, wrap, scale, none |
tablePagination | boolean | true | Enable automatic table pagination |
tableHeaderOnNewPage | boolean | true | Repeat table headers on new pages |
pixelRatio | number | 2 | Image resolution multiplier (1-4) |
quality | number | 0.95 | Image quality for JPEG (0.1-1) |
pageIndex | number | - | 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
}
}
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.
| Value | Description |
|---|---|
pdf | PDF document (default) |
png | PNG image |
jpg | JPEG image |
response
Response encoding type.
| Value | Description |
|---|---|
binary | Raw binary data (default) |
base64 | Base64 encoded string |
textOverflow
How to handle text that exceeds the text box boundaries.
| Value | Description |
|---|---|
truncate | Cut off text that doesn't fit (default) |
wrap | Wrap text to next line |
scale | Scale font size down to fit |
none | Allow 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:
1to4 - Default:
2
quality
JPEG compression quality. Only applies when format is jpg.
- Range:
0.1to1 - 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, orimage/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
}