Skip to content

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

All available helpers (date, numbers, conditions, text, QR code, and more) are documented in the Handlebars Helpers Reference.

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.