A User Role with permissions to manage and generate template that is assigned to the user working with the PDFPlugin.
Manage Templates gives permission to create/edit and delete new PDF templates
Generate Templates gives permission to use the plugin for PDF generation. This permission has to be granted in order to create a PDF inside an application.
Step 1 – Create a new template
To create a new template simply follow these steps:
Access the PDF Plugin’s UI by clicking on the ‘Plugins’ entry from the main menu and then double click on the entry ‘pdfPlugin’ in the plugin list overview (see screenshot above)
A PDFtemplate is build using HTML code to define what should be displayed and how it’s layouted. Values from the JSON data can be accessed using handlebars.
2.2.1 Body
The main part of the template should be in the body of the template. You can use HTML code to define the structure and refer to CSS classes for styling (see Step 2.3).
Example:
<h2> List of articles</h2>
<span>This is a list of articles.</span><br>
<span>The text is static content meaning it's rendered everytime the template is used to create a PDF</span>
<p>The following items are dynamic content meaning they're only rendered if the data is send to the PDFplugin when create a PDF</p>
<table>
<!--This part of the table is static-->
<tr class="tableHeader">
<td>Article number</td>
<td>Title</td>
<td>Price</td>
</tr>
<!--This part of the table is dynamic-->
<!--for every item in our JSON one row will be rendered-->
{{#data}}
<!--only if available == true of entry-->
{{#available}}
<tr>
<!--the value of every item is used and rendered-->
<td>{{articleNumber}}</td>
<td>{{title}}</td>
<td>{{price}}</td>
</tr>
{{/available}}
{{/data}}
</table>
2.2.2 Header / Footer
If a header or footer should be rendered on every page of a PDF, you can define the content in those two tabs. Same as in the body you can use HTML and CSS to define the content.
There is currently one restricition: <!DOCTYPE html> must be inserted before any content!
Example:
<!DOCTYPE html>
<hr>
<span style="color: grey">My Company Name </span>
The library used for rendering the template is not supporting CSS3 features!
The preview and the rendering don’t display the same result. Always test render your PDF.
Step 3 – Configurations for the PDF
The Server-Side Business Object ‘SF_PDF‘ has two functions: ‘generate‘ and ‘generateWithConfig‘.
If you simply want to show your data on a PDF, using the function ‘generate’ will be sufficient. However, if you want to add some configurations, like the page size or page orientation, use ‘generateWithConfig’.
‘GenerateWithConfig’ has an additional parameter: ‘configJSON’. In this parameter, you can set your configurations in JSON format.
Q: How can i enforce a page break after a specific element?
A: Forcing a page break after a specific element is also done by using CSS. Copy and paste the following CSS into your template and add the class to the desired HTML element
.break-after{
page-break-after: always;
}
Q: I want to have the number of pages inside the footer. How can i achieve this?
A: This can be done using functionality of WKHTMLTOPDF. Have a look at the documentation file linked and search for “Footers And Headers”. There’s an example you can simple copy and paste
Restrictions
PDFPlugin templates can not be part of a Simplifier transport and therefore have to be transported manually.