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);
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.
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.