Skip to content

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 #RRGGBB in 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.available has no duplicates and contains locales.default.
  • A translated text ({ "i18n": … }) has the default language and only languages from locales.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.50 prints as 1.5), true/false as words, null as 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 fontFamily falls 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.

FieldTypeValuesDescription
schemaVersion1Version of the format; parseTemplate migrates older versions and refuses newer ones.
kind"pdf"What the template produces.
localesLocales
pagePageSetup
pageslist of Page1–50 itemsThe 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.

FieldTypeValuesDescription
defaultstringpattern ^[a-z]{2,3}(-([A-Z]{2}|[0-9]{3}))?$Used where a text has no translation; one of available.
availablelist of string1–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.

FieldTypeValuesDescription
sizePageSize
orientation"portrait" | "landscape"Portrait puts the shorter side horizontally, landscape the longer one.
marginsMargins

PageSize ​

A standard format or a custom size; the orientation decides which side is the width.

One of:

FieldTypeValuesDescription
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).
FieldTypeValuesDescription
format"custom"
widthnumber1 to 10000Millimetres.
heightnumber1 to 10000Millimetres.

Margins ​

Margins in millimetres; guides in the editor, the output does not clip to them.

FieldTypeValuesDescription
topnumber0 to 10000Millimetres, not negative.
rightnumber0 to 10000Millimetres, not negative.
bottomnumber0 to 10000Millimetres, not negative.
leftnumber0 to 10000Millimetres, not negative.

Page ​

One page and its elements.

FieldTypeValuesDescription
idstringpattern ^[A-Za-z0-9_-]+$, at most 64 charactersUnique within the template (pages and elements).
backgroundPaint or nullFills the whole page; null = none.
elementslist of TextElement or RectangleElement or EllipseElement or LineElementStacking 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.

FieldTypeValuesDescription
type"text"
idstringpattern ^[A-Za-z0-9_-]+$, at most 64 charactersUnique within the template (pages and elements).
namestringat most 200 charactersShown in the content list.
hiddenbooleanNot drawn; still listed in the editor.
lockedbooleanLocked in the editor; no effect on the output.
xnumber-10000 to 10000Left edge of the box before rotation, mm from the left edge of the page.
ynumber-10000 to 10000Top edge of the box before rotation, mm from the top edge of the page.
widthnumber0 to 10000Millimetres, not negative.
heightnumber0 to 10000Millimetres, not negative.
rotationnumber-360 to 360Degrees, clockwise, around the centre.
fillPaint or nullFill of the box; null = none.
strokeStroke or nullOutline of the box; null = none.
contentlist of Paragraph or I18nText1–1000 itemsParagraphs for every language, or paragraphs per language.
fontFamilystring1–100 charactersFont family name; an unknown one falls back to the default font.
fontWeightinteger100 to 900, steps of 100100 (thin) to 900 (black) in steps of 100; 400 is regular, 700 bold.
italicbooleanItalic style.
fontSizenumber1 to 1000Font size in points.
lineHeightnumber0.5 to 5Line height as a multiple of the font size.
letterSpacingnumber-50 to 200Letter spacing in % of the font size.
colorstringpattern ^#[0-9A-F]{6}$Text colour, #RRGGBB, upper case.
opacitynumber0 to 100Opacity 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.

FieldTypeValuesDescription
type"rectangle"
idstringpattern ^[A-Za-z0-9_-]+$, at most 64 charactersUnique within the template (pages and elements).
namestringat most 200 charactersShown in the content list.
hiddenbooleanNot drawn; still listed in the editor.
lockedbooleanLocked in the editor; no effect on the output.
xnumber-10000 to 10000Left edge of the box before rotation, mm from the left edge of the page.
ynumber-10000 to 10000Top edge of the box before rotation, mm from the top edge of the page.
widthnumber0 to 10000Millimetres, not negative.
heightnumber0 to 10000Millimetres, not negative.
rotationnumber-360 to 360Degrees, clockwise, around the centre.
fillPaint or nullFill of the box; null = none.
strokeStroke or nullOutline of the box; null = none.
cornerRadiusnumber0 to 5000Millimetres.

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.

FieldTypeValuesDescription
type"ellipse"
idstringpattern ^[A-Za-z0-9_-]+$, at most 64 charactersUnique within the template (pages and elements).
namestringat most 200 charactersShown in the content list.
hiddenbooleanNot drawn; still listed in the editor.
lockedbooleanLocked in the editor; no effect on the output.
xnumber-10000 to 10000Left edge of the box before rotation, mm from the left edge of the page.
ynumber-10000 to 10000Top edge of the box before rotation, mm from the top edge of the page.
widthnumber0 to 10000Millimetres, not negative.
heightnumber0 to 10000Millimetres, not negative.
rotationnumber-360 to 360Degrees, clockwise, around the centre.
fillPaint or nullFill of the box; null = none.
strokeStroke or nullOutline 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).

FieldTypeValuesDescription
type"line"
idstringpattern ^[A-Za-z0-9_-]+$, at most 64 charactersUnique within the template (pages and elements).
namestringat most 200 charactersShown in the content list.
hiddenbooleanNot drawn; still listed in the editor.
lockedbooleanLocked in the editor; no effect on the output.
x1number-10000 to 10000Start point, mm from the left edge of the page.
y1number-10000 to 10000Start point, mm from the top edge of the page.
x2number-10000 to 10000End point, mm from the left edge of the page.
y2number-10000 to 10000End point, mm from the top edge of the page.
strokeStrokeThe 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.

FieldTypeValuesDescription
pieceslist of TextPiece or FieldPieceat most 200 itemsStatic text and placeholders, joined without spaces; empty = an empty line.

TextPiece ​

Static text, printed as is ("{{" in it is just text).

FieldTypeValuesDescription
type"text"
textstringpattern ^[^\r\n]*$Without line breaks; a new line is a new paragraph.

FieldPiece ​

A placeholder, filled from the data at the given path.

FieldTypeValuesDescription
type"field"
pathstringpattern ^[A-Za-z0-9_]+(\.[A-Za-z0-9_]+)*$, at most 200 charactersData path, e.g. customer.name or items.0.price.

I18nText ​

Text per language, each with its own placeholders and word order.

FieldTypeValuesDescription
i18nobject: language → list of ParagraphParagraphs 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.

FieldTypeValuesDescription
colorstringpattern ^#[0-9A-F]{6}$#RRGGBB, upper case.
opacitynumber0 to 100Opacity in %, 0–100.

Stroke ​

An outline or line stroke.

FieldTypeValuesDescription
colorstringpattern ^#[0-9A-F]{6}$#RRGGBB, upper case.
opacitynumber0 to 100Opacity in %, 0–100.
widthnumberabove 0 to 100Stroke width in points, above 0 (no stroke is null).
style"solid" | "dashed" | "dotted"Dashes and dots scale with the stroke width.