Code Snippets-invoice-pdf-generation

Invoice PDF Generation with Make.com

Here we show you how to create a function in CustomJS that generates an Invoice PDF and sends it back to Make.com. 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 parameters also appear automatically when the function is loaded in Make.com.

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 below.

FYI: You can also trigger and generate the PDFs externally without Make.com as an API: Learn more
Invoice Template
Invoice Template



JavaScript Code

This is the JavaScript code to replace the variables in the HTML template with Nunjucks and then return it as a 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 is a screenshot of what the whole function looks like in CustomJS. At the end of the page you will also get an import code to easily import the whole function.

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



Use in Make.com

This is what it looks like in Make.com if you have selected the function to create Inovice PDFs in Make.com via the CustomJS module “Execute a stored function”.

You can see how 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, but below you will also get an import code to import all the settings. You can find the import code in the invoice.html.



Import Code

This is the import code to easily import the example of generating an invoice using Make.com into a 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 the importCode.json.
Import Code
Import Code