Document definition
Templates
Templates define the overall structure, layout, and logic of a document.
They bring together Blocks, Elements, and Regions to form a complete, renderable document.
Templates are the top-level containers from which actual PDFs are generated.
Characteristics
- Structural definition – They describe how content is organized on each page.
- Composable – Include Blocks, Elements, and fixed-position Regions.
- Reusable – Can be used to generate many documents by injecting data.
- Dynamic – Often parameterized to handle variable content and data-driven rendering.
What a Template Can Contain
- Blocks – Reusable layout pieces with dynamic or static content.
- Elements – Primitive visual or textual components.
- Regions – Absolutely positioned areas for fixed content (e.g., address fields).
Example Template Structure
{
"type": "template",
"name": "invoice_layout",
"content": [
{ "type": "block", "use": "header" },
{ "type": "block", "use": "invoice_items", "data": "{{items}}" },
{ "type": "block", "use": "footer" }
],
"regions": [
{
"type": "region",
"x": 40,
"y": 50,
"width": 200,
"height": 60,
"children": [
{ "type": "block", "use": "address" }
]
}
]
}
When to Use Templates
Use Templates to:
- Define a full document layout.
- Compose and arrange reusable Blocks and content logic.
- Manage page-level configuration, such as margins, orientation, or fixed fields.
- Apply styling, structure, and flow control for final rendering.
Document Generation Flow
- Define Blocks and Regions
- Combine them in a Template
- Inject tokens
- Generate the final Document
Templates are the bridge between design and output. They transform layout definitions into complete PDF documents.