PDF Templates are used within the DataEngine to generate PDF files for specific modules that can be downloaded or sent. For a DataEngine module, multiple templates can be configured with different contents and purposes. Within the template, data from the module as well as data from related modules can be used. Simplified conditions can be used to control how a PDF file is structured.
Module Setup
To utilize the PDF Template function, the module must be set up accordingly. Follow these steps:
- Go to the Admin area and select “Developer Tools” > “Dropdown Editor”.
- Edit the dropdown with the name ‘pdf_template_type_dom’.
- Enter the desired module name in the ‘Item Name’ field, e.g., core_Deals.
- Enter the name under which the module should appear in the selection in the ‘Display Label’ field, e.g., Deals.
- Click the ‘Add’ button to add as many modules as needed.
- Save the changes by clicking the ‘Save’ button.
Now, PDF Templates can be created for the configured modules.
Template Sections
A PDF Template consists of various sections:
- Body: This section is generated and distributed over multiple pages if it doesn’t fit on one page.
- Header: This section is repeated on every page of the generated PDF if there are multiple pages.
- Footer: This section is repeated on every page of the generated PDF if there are multiple pages.
Template Variables
Variables can be used in the editor, having the form ‘$module_field’. The editor displays all possible variables for selection during setup.
Additionally, it is possible to add a post-processor to the template variable by using the “|” symbol. Currently, two post-processors are available:
number(seperator;thousand;decimal)
: This post-processor formats the value as a number and allows for the specification of thousand separators and decimal points. For example,$module_field|number(,;.;2)
formats the value as a number with 2 decimal places in the German format (2.314,65).date(format)
: This post-processor formats the value as a date according to the specified format. For example,$module_field|date(m/d/y)
formats the value as a date in the format MM/DD/YY (04/19/2024). The format used internally is based on the PHP date formats as described in the PHP date format documentation.
Template Conditions
PDF Templates support a simplified condition syntax. This can be used to hide specific sections in the generated PDF. For example, a Deal Report could display different information depending on the Sales Stage.
Here are some examples of the condition syntax:
Simple Case:
{% if $variable == 'test' %} Display this part {% endif %}
Case with ‘else’:
{% if $variable == 'test' %} Display this part {% else %} Otherwise, display this part {% endif %}
Conditions can be used in the Header, Footer, and Body Templates. Currently, only the ‘==’ operator is supported. All variables from the PDF Template Editor can be used. Please note that conditions cannot be nested at the moment.
Template Styling
1. Inline Styling in the PDF Template
Inline styling involves adding CSS styles directly within the HTML of the PDF template. This method allows for quick and specific styling adjustments but can become cumbersome for larger templates or when consistent styling is needed across multiple templates.
Example:
<p style="font-size: 12pt; color: #333;">This is a styled paragraph.</p>
2. Global Styling for All PDF Templates
Global styling can be applied to all PDF templates via the Admin panel. This method ensures a consistent look and feel across all templates and simplifies the management of styles.
To apply global styling:
- Navigate to Admin → CSS → CSS PDF.
- Add your CSS styles in the provided editor. These styles will be applied to all PDF templates.
The default font can only be changed via the mPDF configuration!
Example:
body {
font-size: 12pt;
color: #333;
}
h1 {
font-size: 24pt;
color: #000;
}
3. Configuration of mPDF
Advanced styling and configuration options can be achieved by configuring mPDF settings. This method allows for detailed customization, including setting default fonts, font directories, and other PDF generation options. For detailed information on mPDF configuration, refer to the mPDF documentation at https://marini.systems/de/help-center/docs/custom-config/.
Example:
{
"mpdf": {
"default_font": "helvetica",
"fontDir": [
"custom/fonts"
],
"fontdata": {
"helvetica": {
"R": "Helvetica.ttf"
}
}
}
}
This configuration sets the default font to helvetica
and specifies the directory for custom fonts. The Helvetica.ttf
file is used as the regular font for the Helvetica typeface.