Skip to main content

Templating

We have a powerful templating system which allows you to use pre-defined templates that you can browse in our PDF template gallery or the Image template gallery. Once you have found a template to use, you can pass in the templateId and your data, and we handle the rest.

In addition, we also support custom templating where you can create your own templates.

All templates have the following features:

  • Powerful Nunjucks Templating
  • Fast and Accurate Generation
  • Stored in our global edge-based CDN
  • Thumbnail Generation (optional)
  • Multicultural Support such as currency, time, full UTF-8
  • Auto calculations, if available in the template
  • Local caching for high-speed rendering
  • Built-in Tailwind CSS support
  • All PDF Templates support smart page breaking for printing

Auto Calculation

If you use a predefined template from the gallery that supports auto calculations, you have a couple of options to control the behavior.

Enabled/Disable

To enable or disable, you need to set the __auto_calculate field in the data provided to either true or false.

info

Disabling auto-calculation can be helpful if you do the calculations on your end and do not want the template to do them.

Auto Calculated fields

The values for auto-calculated fields will be any field marked as null in the sample data provided. If you set the field __auto_calculate: false in the data, it will simply pass the data supplied to it.

Template Types

Two types of templates are available: predefined templates you choose from the template gallery or custom templates which are templates that you create yourself using the templating system.

Predefined Templates

The most accessible and convenient approach is to use one of our professional and beautiful-looking predefined templates. Expertly created and curated to offer the best solution.

  1. Choose a PDF Template or Image Template from the template gallery.
  2. Use the JSON example code offered to you in the template gallery or copy the templateId out of it and craft your request.
  3. In the JSON example code, sample data is used as an example to understand what data elements are supported by the template.

Read more about Predefined Templates in the API documentation.

Custom Templates

If you need more flexibility than Predefined template, you can create your own templates using the Nunjucks syntax and pass in your data.

Read more about Custom Templates in the API documentation.

Functions

We offer several functions that we have extended Nunjucks with to offer greater flexibility around multicultural support currencies, times, etc.

formatCurrency

Formats the Currency string into the cultural variant.

formatCurrency(locale, currency, amount);
Example - Template
<html>
<body>
{{formatCurrency(locale, currency, amount)}}
</body>
</html>
Example - Data
{
"locale": "en-GB",
"currency": "EUR",
"amount": 150.1
}
Result
€150.10

locale

Unicode locale identifier. For more info on locale identifiers.

currency

The currency format identifier. For a list of support currencies.

amount

The amount in whole numbers or decimal notation.

formatDateTime

Formats the DateTime string into the cultural variant.

formatDateTime(locale, dateTime);
Example - Template
<html>
<body>
{{formatDateTime(locale, invoice_date)}}
</body>
</html>
Example - Data
{
"locale": "fr_FR",
"invoice_date": "27 March, 2020"
}
Result
27 mars 2020

locale

Unicode locale identifier. For more info on locale identifiers.

dateTime

The string representation of the date.