Invoice PDF Generation

As an example of integrating JavaScript functions into your Make.com workflows, this tutorial shows how to generate Invoice PDFs dynamically. This is useful for automating the generation of invoices in your workflows.

To do this, we have created some dynamic parameters on the right-hand side in the CustomJS platform. These parameters are inserted in the HTML template as variables and are replaced by the template engine Nunjucks during rendering.

The HTML template was created as a static variable with the type HTML so the CustomJS HTML editor can be used as you can see in the screenshot.

Invoice Template
Invoice Template

Workflow overview

1

Parameters — Define dynamic parameters in the CustomJS platform (these will also appear automatically as input fields in Make.com).

2

Template — Insert these parameters into an HTML invoice template, which is rendered with the Nunjucks templating engine.

3

Storage/Editing — Store the template as a static HTML variable, so you can edit it in the CustomJS HTML editor.

4

Output — Generate the final output as a PDF, which you can use in Make.com or trigger externally via the CustomJS API.

You can also generate PDFs externally using CustomJS as an API: Learn more.

JavaScript code

The following script replaces variables in the HTML template with Nunjucks and generates the PDF.

const { HTML2PDF } = require("./utils");
const nunjucks = require("nunjucks");

const content = nunjucks.renderString(variables.Template, {
  currency: "€",
  items: JSON.parse(input.items),
  taxRate: 19,
  subTotal: input.subTotal,
  taxAmount: input.taxAmount,
  total: input.total,
  invoiceNumber: input.invoiceNumber,
  createdDate: input.invoiceDate,
  dueDate: input.invoiceDueDate,
  companyLogo: "https://beta.customjs.space/customJS-logo.png",
  sender: {
    name: "Technology Circle GmbH",
    address1: "Karolinenstraße 24 Haus 4",
    address2: "20357 Hamburg",
    iban: "IBAN SAMPLE",
    bic: "BIC SAMPLE"
  },
  receiver: {
    name: input.clientName,
    address1: input.clientAddress1,
    address2: input.clientAddress2,
    tax: input.clientTax,
  },
  footerText: "2025© TechnologyCircle",
});

return await HTML2PDF(content);

CustomJS platform

Here’s how the full function looks inside CustomJS.

Generate Invoices With Make.com
Generate Invoices With Make.com

Use in Make.com

In Make.com, select the Execute a stored function CustomJS module to create Invoice PDFs.

The dynamic parameters automatically appear as input fields in Make.com
Usage in Make.com
Usage in Make.com

HTML template

This is the HTML code of the Invoices. You can find the import code in the invoice.html.

Import code

You can import this entire setup into a new CustomJS function. To do this, create an empty function and then select the import button from the context menu. You can find the import code in importCode.json.
Import Code
Import Code