Working with Templates
Learn how to use templates when generating documents via the RenderDoc API.
Overview
Templates in RenderDoc are pre-designed document formats created in the dashboard. When generating documents via API, you reference these templates by their ID and provide variables for personalization.
Template Management: Templates can be created, updated, and deleted via both the Dashboard UI and JWT-authenticated API endpoints. The Dashboard provides a visual designer for easier template creation, while the API allows programmatic management for automation and integration purposes.
How Templates Work
1. Create Templates
Templates can be created in two ways:
Option A: Dashboard (Recommended for Design)
- Navigate to Templates in the dashboard
- Click Create Template
- Use the visual drag-and-drop designer
- Define variables for dynamic content
- Save and publish your template
See the Templates User Guide for detailed instructions.
Option B: API (For Automation)
- Use JWT-authenticated API endpoints
- Programmatically create and manage templates
- Ideal for CI/CD pipelines and automated workflows
- Requires template schema knowledge
See the API Reference - Templates for API documentation.
2. Use Templates for Document Generation
Once templates are created, reference them in API calls:
{
templateId: 'tmpl_invoice', // Required - references dashboard template
format: 'pdf', // or 'xlsx'
variables: { // Fills in template placeholders
invoiceNumber: 'INV-001',
customerName: 'Acme Corp',
amount: 1250.00
}
}
Template Types
RenderDoc supports two output formats from templates:
PDF Templates
Used for generating professional PDF documents:
- Text, headings, paragraphs
- Images and logos
- Tables for data display
- Conditional blocks
- Loops for repeating content
- Native charts (bar, line, pie, area, scatter)
- Page breaks and headers/footers
Usage:
curl https://api.renderdoc.dev/api/v1/documents/generate \
-H "Authorization: Bearer rd_sk_abc123..." \
-H "Content-Type: application/json" \
-X POST \
-d '{
"templateId": "tmpl_invoice",
"format": "pdf",
"variables": { "invoiceNumber": "INV-001" }
}'
Excel Templates
Used for generating Excel spreadsheets:
- All PDF components plus:
- Native charts with Excel interactivity
- Advanced table formatting with calculated columns
- Multiple sheets
- Formula support
Usage:
const result = await client.documents.generate({
templateId: 'tmpl_monthly_report',
format: 'xlsx',
variables: {
reportMonth: 'January 2025',
data: [
{ category: 'Sales', amount: 50000 },
{ category: 'Expenses', amount: 30000 }
]
}
});