PDF Templates
PDF Templates is a special class that contains all the template instances you create using the PDF Template Editor. Each instance holds the specific fillTemplate
function for its corresponding layout. For a full guide on how to visually design a template, please refer to the main PDF Template Editing article. This document focuses on how to use the function in your backend logic.
fillTemplate
fillTemplate
The fillTemplate
function is the engine that programmatically merges your application's data with a pre-designed PDF layout to generate a finished document.
Input
The function has two inputs: a required data object and an optional configuration object.
Values (required): A standard data object with key-value pairs. The keys in this object (e.g.,
firstName
,orderDate
) must exactly match the variable names you configured for the placeholders in the Template Editor.Options (optional): A JSON object for configuring the function's behavior. It has one property:
showEmptyVariables
: Set totrue
to displaynull
orundefined
on the final PDF if a placeholders value is undefined in the data object. Defaults tofalse
, which shows nothing for empty values.
Example:
#values
name: John
surname: Doe
signature: data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
#options
showEmptyVariables: true
Output
The function provides the finished, populated PDF document as a Base64 encoded string. While designing your logic, the function output itself will show a preview of the rendered PDF with your template's layout. The output can be used to store in a database, visualize in a media view widget, send in an email or in any other way you like.
The function provides the finished, populated PDF document as a Base64 encoded string. While designing your logic, the function block itself will show a preview of the rendered PDF with your template's layout. The output can be used to store the document in a database, visualize it in the media view widget, send it as an email attachment, or process it further in any other way your application requires.

Important Notes
Data is Overwritten: Each execution of the
fillTemplate
function generates a brand new document and completely overwrites all fields.Fill All at Once: The function is designed to populate the entire template in a single operation.
Complex Data: For templates with many fields, it is a best practice to first gather all the necessary data into a single, structured object before passing it to the function.
User-Specific Documents: Each output is a separate document isolated for the user session that triggered the function.
Full Tutorial
To see the PDF Templates class in action, follow our complete step-by-step guide where we build a dynamic acceptance report from start to finish.
Last updated