Generate PDF from Handlebars template
The “Generate PDF from template (Handlebars)” service task creates a PDF document from an HTML template. The template is rendered with Handlebars to inject dynamic content – ideal for invoices, quotes, or reports.
Input parameters
Provide the following fields as task input:
{
"filename": "document.pdf",
"content": {
"customerName": "Jane Doe",
"invoiceNumber": "12345",
"totalAmount": 500.00
},
"templateHtml": "<html><body><h1>Invoice {{invoiceNumber}}</h1><p>Customer: {{customerName}}</p><p>Amount: {{totalAmount}} EUR</p></body></html>"
}
Explanation:
filename
: Desired filename of the generated PDF document.content
: Data to inject into the HTML template.templateHtml
: HTML template with Handlebars placeholders.
Output
The task returns a reference to the generated PDF document.
{
"status": 200,
"response": {
"fileReference": "s3://bucket-name/document.pdf"
}
}
Explanation:
status
: Status of the operation (200
indicates success).fileReference
: File reference to the generated PDF document.
JSONata examples
{
"filename": "invoice-{{$.orderDetails.orderId}}.pdf",
"content": {
"customerName": $.customer.name,
"invoiceNumber": $.orderDetails.orderId,
"totalAmount": $.orderDetails.totalAmount
},
"templateHtml": "<html><body><h1>Invoice {{invoiceNumber}}</h1><p>Customer: {{customerName}}</p><p>Amount: {{totalAmount}} EUR</p></body></html>"
}
Available Handlebars helpers
Helper | Description | Example |
---|---|---|
dateTimeFormat |
Formats an ISO-8601 date into a localized date and time. | {{dateTimeFormat '2024-12-22T10:30:00Z' 'en-US' 'Europe/Berlin'}} |
multiply |
Multiplies two numbers. | {{multiply 5 3}} |
currentDateTime |
Returns the current date and time in the specified format. | {{currentDateTime 'en-US' 'Europe/Berlin'}} |
toGermanDate |
Converts a date in YYYY-MM-DD to the German date format. |
{{toGermanDate '2024-12-22'}} |
replace |
Replaces a string with another value. | {{replace 'Pantarey GmbH' 'GmbH' 'AG'}} |
add |
Adds two numbers. | {{add 10 5}} |
round |
Rounds a number to a specific number of decimal places. | {{round 12.3456 2}} |
currency_eur |
Formats a number as a Euro amount in the German locale. | {{currency_eur 1234.56}} |
addDaysToCurrentDate |
Adds a number of days to the current date. | {{addDaysToCurrentDate 5}} |
month_name |
Returns the month name based on a date. | {{month_name '2024-12-22'}} |
greaterThan |
Checks if the first number is greater than the second. | {{#greaterThan 10 5}}Greater{{else}}Not greater{{/greaterThan}} |
lessThan |
Checks if the first number is less than the second. | {{#lessThan 3 5}}Less{{else}}Not less{{/lessThan}} |
greaterOrEqualThan |
Checks if the first number is greater than or equal to the second. | {{#greaterOrEqualThan 5 5}}Greater or equal{{else}}Not greater or equal{{/greaterOrEqualThan}} |
lessOrEqualThan |
Checks if the first number is less than or equal to the second. | {{#lessOrEqualThan 3 5}}Less or equal{{else}}Not less or equal{{/lessOrEqualThan}} |
numberFormat |
Formats a number using the German number format. | {{numberFormat 1234567.89}} |
Notes
- Use Handlebars placeholders in
templateHtml
to insert dynamic content. - Leverage the helpers to format values conveniently.
- Ensure the data in
content
is formatted correctly. - The PDF is generated in the background and returned as a file reference.
Tip
Use JSONata to build content
and filename
dynamically from process data.