Template format
A Templo template is one JSON document. The editor edits it, the render API takes it, and the same document always gives the same output. This page describes schemaVersion 1. A JSON Schema (draft 2020-12) of it is published as well.
Conventions
- Units: positions, sizes, margins and corner radius in millimetres, measured from the top-left corner of the page. Font size and stroke width in points. Rotation in degrees, clockwise, around the centre of the element.
- Colours are
#RRGGBBin upper case; opacity is a percentage, 0–100. - Every key is required. An empty optional value is
null, never a missing key. - Unknown keys are errors. New fields come with a new
schemaVersion.
Rules the JSON Schema can't express
parseTemplate, and so the API, checks them too: a template that breaks one is rejected with an error that names the field.
- Ids are unique across the whole template, pages and elements together.
- At most 1000 elements across all pages, and 10000 characters per text and language (static text plus placeholder paths).
locales.availablehas no duplicates and containslocales.default.- A translated text (
{ "i18n": … }) has the default language and only languages fromlocales.available.
Placeholders
A field piece ({ "type": "field", "path": "customer.name" }) prints the value at that path in the data. Segments are object keys or list positions: items.0.price is the price of the first item.
- Strings print as they are, numbers as plain digits (
1.50prints as1.5),true/falseas words,nullas nothing. There is no formatting yet: send amounts and dates as display strings. - A path with no value, or a value that is an object or a list, prints nothing and the render reports a warning.
- Static text is never interpreted:
{{or any other syntax in it is printed as is.
Languages
locales lists the template's languages. A text's content is either paragraphs for every language or { "i18n": { "<language>": paragraphs } }, each language with its own placeholders and word order. When rendering in a language, a text uses that language, then the language without its region (de-AT → de), then another region of the same language, then locales.default.
Versions
schemaVersion is the version of this format. Older versions are migrated on read; a template from a newer version is refused.
Layout
- Elements are drawn in the order of
elements: the first at the bottom, the last on top. Hidden elements are not drawn. - Elements may extend past the edge of the page; only what is on the page is visible. Margins are guides in the editor and don't clip anything.
- Text that doesn't fit its box runs past the bottom of the box, and the render reports a warning.
- An unknown
fontFamilyfalls back to the default font, with a warning.
Types
PdfTemplate · Locales · PageSetup · PageSize · Margins · Page · TextElement · RectangleElement · EllipseElement · LineElement · Paragraph · TextPiece · FieldPiece · I18nText · Paint · Stroke
PdfTemplate
A PDF template.
| Field | Type | Values | Description |
|---|---|---|---|
schemaVersion | 1 | Version of the format; parseTemplate migrates older versions and refuses newer ones. | |
kind | "pdf" | What the template produces. | |
locales | Locales | ||
page | PageSetup | ||
pages | list of Page | 1–50 items | The pages, in order. |
Example:
json
{
"schemaVersion": 1,
"kind": "pdf",
"locales": {"default": "de", "available": ["de", "de-AT", "en"]},
"page": {
"size": {"format": "custom", "width": 150, "height": 200},
"orientation": "landscape",
"margins": {"top": 10, "right": 12, "bottom": 10, "left": 12}
},
"pages": [
{
"id": "shapes",
"background": null,
"elements": [
{
"type": "text",
"id": "right",
"name": "Right",
"hidden": false,
"locked": false,
"x": 16,
"y": 42,
"width": 72,
"height": 8,
"rotation": 0,
"fill": null,
"stroke": null,
"content": [
{
"pieces": [
{"type": "text", "text": "Price "},
{"type": "field", "path": "items.0.price"}
]
}
],
"fontFamily": "Instrument Sans",
"fontWeight": 300,
"italic": false,
"fontSize": 10,
"lineHeight": 1.2,
"letterSpacing": 0,
"color": "#B5563A",
"opacity": 60,
"align": "right"
}
]
}
]
}Locales
Languages of the template.
| Field | Type | Values | Description |
|---|---|---|---|
default | string | pattern ^[a-z]{2,3}(-([A-Z]{2}|[0-9]{3}))?$ | Used where a text has no translation; one of available. |
available | list of string | 1–20 items, each pattern ^[a-z]{2,3}(-([A-Z]{2}|[0-9]{3}))?$ | The languages of the template, without duplicates. |
PageSetup
Page setup shared by all pages.
| Field | Type | Values | Description |
|---|---|---|---|
size | PageSize | ||
orientation | "portrait" | "landscape" | Portrait puts the shorter side horizontally, landscape the longer one. | |
margins | Margins |
PageSize
A standard format or a custom size; the orientation decides which side is the width.
One of:
| Field | Type | Values | Description |
|---|---|---|---|
format | "A3" | "A4" | "A5" | "Letter" | "Legal" | A standard format (portrait width × height: A3 297 × 420 mm, A4 210 × 297 mm, A5 148 × 210 mm, Letter 215.9 × 279.4 mm, Legal 215.9 × 355.6 mm). |
| Field | Type | Values | Description |
|---|---|---|---|
format | "custom" | ||
width | number | 1 to 10000 | Millimetres. |
height | number | 1 to 10000 | Millimetres. |
Margins
Margins in millimetres; guides in the editor, the output does not clip to them.
| Field | Type | Values | Description |
|---|---|---|---|
top | number | 0 to 10000 | Millimetres, not negative. |
right | number | 0 to 10000 | Millimetres, not negative. |
bottom | number | 0 to 10000 | Millimetres, not negative. |
left | number | 0 to 10000 | Millimetres, not negative. |
Page
One page and its elements.
| Field | Type | Values | Description |
|---|---|---|---|
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
background | Paint or null | Fills the whole page; null = none. | |
elements | list of TextElement or RectangleElement or EllipseElement or LineElement | Stacking order: the first element is at the bottom, the last on top. |
TextElement
A text box: paragraphs of static text and placeholders, one style. Text that does not fit runs past the bottom of the box.
| Field | Type | Values | Description |
|---|---|---|---|
type | "text" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x | number | -10000 to 10000 | Left edge of the box before rotation, mm from the left edge of the page. |
y | number | -10000 to 10000 | Top edge of the box before rotation, mm from the top edge of the page. |
width | number | 0 to 10000 | Millimetres, not negative. |
height | number | 0 to 10000 | Millimetres, not negative. |
rotation | number | -360 to 360 | Degrees, clockwise, around the centre. |
fill | Paint or null | Fill of the box; null = none. | |
stroke | Stroke or null | Outline of the box; null = none. | |
content | list of Paragraph or I18nText | 1–1000 items | Paragraphs for every language, or paragraphs per language. |
fontFamily | string | 1–100 characters | Font family name; an unknown one falls back to the default font. |
fontWeight | integer | 100 to 900, steps of 100 | 100 (thin) to 900 (black) in steps of 100; 400 is regular, 700 bold. |
italic | boolean | Italic style. | |
fontSize | number | 1 to 1000 | Font size in points. |
lineHeight | number | 0.5 to 5 | Line height as a multiple of the font size. |
letterSpacing | number | -50 to 200 | Letter spacing in % of the font size. |
color | string | pattern ^#[0-9A-F]{6}$ | Text colour, #RRGGBB, upper case. |
opacity | number | 0 to 100 | Opacity in %, 0–100. |
align | "left" | "center" | "right" | "justify" | Horizontal alignment; justify leaves the last line of a paragraph left-aligned. |
Example:
json
{
"type": "text",
"id": "right",
"name": "Right",
"hidden": false,
"locked": false,
"x": 16,
"y": 42,
"width": 72,
"height": 8,
"rotation": 0,
"fill": null,
"stroke": null,
"content": [
{
"pieces": [
{"type": "text", "text": "Price "},
{"type": "field", "path": "items.0.price"}
]
}
],
"fontFamily": "Instrument Sans",
"fontWeight": 300,
"italic": false,
"fontSize": 10,
"lineHeight": 1.2,
"letterSpacing": 0,
"color": "#B5563A",
"opacity": 60,
"align": "right"
}RectangleElement
A rectangle.
| Field | Type | Values | Description |
|---|---|---|---|
type | "rectangle" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x | number | -10000 to 10000 | Left edge of the box before rotation, mm from the left edge of the page. |
y | number | -10000 to 10000 | Top edge of the box before rotation, mm from the top edge of the page. |
width | number | 0 to 10000 | Millimetres, not negative. |
height | number | 0 to 10000 | Millimetres, not negative. |
rotation | number | -360 to 360 | Degrees, clockwise, around the centre. |
fill | Paint or null | Fill of the box; null = none. | |
stroke | Stroke or null | Outline of the box; null = none. | |
cornerRadius | number | 0 to 5000 | Millimetres. |
Example:
json
{
"type": "rectangle",
"id": "card",
"name": "Card",
"hidden": false,
"locked": false,
"x": 12,
"y": 10,
"width": 80,
"height": 50,
"rotation": 0,
"fill": {"color": "#F4EFE6", "opacity": 100},
"stroke": {"color": "#2A2119", "opacity": 100, "width": 1, "style": "solid"},
"cornerRadius": 4
}EllipseElement
An ellipse filling its box.
| Field | Type | Values | Description |
|---|---|---|---|
type | "ellipse" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x | number | -10000 to 10000 | Left edge of the box before rotation, mm from the left edge of the page. |
y | number | -10000 to 10000 | Top edge of the box before rotation, mm from the top edge of the page. |
width | number | 0 to 10000 | Millimetres, not negative. |
height | number | 0 to 10000 | Millimetres, not negative. |
rotation | number | -360 to 360 | Degrees, clockwise, around the centre. |
fill | Paint or null | Fill of the box; null = none. | |
stroke | Stroke or null | Outline of the box; null = none. |
Example:
json
{
"type": "ellipse",
"id": "badge",
"name": "Badge",
"hidden": false,
"locked": false,
"x": 150,
"y": 12,
"width": 30,
"height": 30,
"rotation": 0,
"fill": {"color": "#4F7A6B", "opacity": 80},
"stroke": null
}LineElement
A straight line from (x1, y1) to (x2, y2).
| Field | Type | Values | Description |
|---|---|---|---|
type | "line" | ||
id | string | pattern ^[A-Za-z0-9_-]+$, at most 64 characters | Unique within the template (pages and elements). |
name | string | at most 200 characters | Shown in the content list. |
hidden | boolean | Not drawn; still listed in the editor. | |
locked | boolean | Locked in the editor; no effect on the output. | |
x1 | number | -10000 to 10000 | Start point, mm from the left edge of the page. |
y1 | number | -10000 to 10000 | Start point, mm from the top edge of the page. |
x2 | number | -10000 to 10000 | End point, mm from the left edge of the page. |
y2 | number | -10000 to 10000 | End point, mm from the top edge of the page. |
stroke | Stroke | The line itself. | |
cap | "butt" | "round" | "square" | Shape of the line ends: butt stops at the end point, round and square reach past it. |
Example:
json
{
"type": "line",
"id": "divider",
"name": "Divider",
"hidden": false,
"locked": false,
"x1": 12,
"y1": 70,
"x2": 188,
"y2": 70,
"stroke": {"color": "#2A2119", "opacity": 100, "width": 0.5, "style": "solid"},
"cap": "butt"
}Paragraph
One paragraph; a line break in a text starts a new one.
| Field | Type | Values | Description |
|---|---|---|---|
pieces | list of TextPiece or FieldPiece | at most 200 items | Static text and placeholders, joined without spaces; empty = an empty line. |
TextPiece
Static text, printed as is ("{{" in it is just text).
| Field | Type | Values | Description |
|---|---|---|---|
type | "text" | ||
text | string | pattern ^[^\r\n]*$ | Without line breaks; a new line is a new paragraph. |
FieldPiece
A placeholder, filled from the data at the given path.
| Field | Type | Values | Description |
|---|---|---|---|
type | "field" | ||
path | string | pattern ^[A-Za-z0-9_]+(\.[A-Za-z0-9_]+)*$, at most 200 characters | Data path, e.g. customer.name or items.0.price. |
I18nText
Text per language, each with its own placeholders and word order.
| Field | Type | Values | Description |
|---|---|---|---|
i18n | object: language → list of Paragraph | Paragraphs per language; the default language is required. |
Example:
json
{
"i18n": {
"de": [
{
"pieces": [
{"type": "text", "text": "Hallo "},
{"type": "field", "path": "customer.name"}
]
}
],
"de-AT": [
{
"pieces": [
{"type": "text", "text": "Servus "},
{"type": "field", "path": "customer.name"}
]
}
],
"en": [
{
"pieces": [
{"type": "text", "text": "Hello "},
{"type": "field", "path": "customer.name"}
]
}
]
}
}Paint
A colour with opacity.
| Field | Type | Values | Description |
|---|---|---|---|
color | string | pattern ^#[0-9A-F]{6}$ | #RRGGBB, upper case. |
opacity | number | 0 to 100 | Opacity in %, 0–100. |
Stroke
An outline or line stroke.
| Field | Type | Values | Description |
|---|---|---|---|
color | string | pattern ^#[0-9A-F]{6}$ | #RRGGBB, upper case. |
opacity | number | 0 to 100 | Opacity in %, 0–100. |
width | number | above 0 to 100 | Stroke width in points, above 0 (no stroke is null). |
style | "solid" | "dashed" | "dotted" | Dashes and dots scale with the stroke width. |