Multi-page product invoice

Order lines, computed totals and a color theme from your data

Generate PDF invoices from your application

E-commerce platforms, ERPs and billing tools send each order to the Carbone API as JSON and get the invoice back as a PDF. An invoice lists a variable number of products, shows totals that are not always in the data, and must stay readable when the product table spans several pages. Here, a French supplier bills a customer for 34 order lines: the DOCX template repeats a row per product, computes the line totals, the VAT by rate and the amount due, and applies the brand color defined in the JSON data. It carries the mentions of a French B2B invoice: invoice number, issue and supply dates, seller and buyer SIREN and VAT numbers, payment terms and the late payment penalties.

In this example, you will:

  • Repeat a table row for each product, with its picture, EAN-13 barcode and line total
  • Store the line totals and VAT amounts in the JSON data with :set, then sum them by VAT rate
  • Repeat the table header on each page and print "Page X of Y"
  • Apply the brand color and banded rows from the JSON data

How to build a multi-page invoice template

Follow these steps to build the invoice template:

1. Lay Out the Header and the Product Table

In Word, create the header of the invoice: the logo, the invoice number, then a three-column block with the seller, the customer and the invoice details. Below, insert a product table with a header row, a column for each product detail (picture, description, barcode, unit price, quantity, VAT rate and total), and a small table for the VAT summary and the amount due.

To number the pages, open the footer, then click Insert > Quick Parts > Field and insert Page and NumPages: the footer prints "Page 1 of 3".

2. Insert the Company and Customer Data

Display the data with Carbone tags, for example:

{d.company.name} {d.company.legalForm}
{d.company.address}
{d.company.postalCode} {d.company.city}, {d.company.country}
VAT ID {d.company.vatId}

Format the dates with {d.date:formatD(LL)}. For the logo, insert a placeholder image, right-click it, choose View Alt Text, and enter {d.company.logo}.

3. Repeat a Row per Product

In the second row of the product table, create a loop: {d.products[i].name}, {d.products[i].priceUnit:formatN(2)}, {d.products[i].quantity}, {d.products[i].vatRate} and the line total {d.products[i].priceUnit:mul(.quantity):formatN(2)}. In the third row, add {d.products[i+1].name} to mark the end of the loop.

In the picture and barcode columns of the same row, insert a placeholder image and set its Alt Text:

  • {d.products[i].image} for the product picture
  • {d.products[i].barcode_ean13:barcode(ean13, scale:6):imageFit(contain)} for the barcode, generated from the 13 digits of the product code

To keep the table readable over several pages, open Table Properties:

  • Select the first row, and in the Row tab, check Repeat as header row at the top of each page
  • Select the loop row, and uncheck Allow row to break across pages

4. Compute the Totals and the VAT

In the row that ends the loop, store the amounts in each product with the :set formatter. These tags add the attributes priceTotal, vatAmount and priceGross to each product of the JSON data, and print nothing in the generated document:

{d.products[].priceUnit:mul(.quantity):set(.priceTotal)}
{d.products[].priceUnit:mul(.quantity):mul(.vatRate):div(100):set(.vatAmount)}
{d.products[].priceTotal:add(.vatAmount):set(.priceGross)}

In the VAT summary, sum the stored values with :aggSum, and use an array filter to total one VAT rate per row. For the 20 % row:

{d.products[vatRate=20].priceTotal:aggSum:formatN(2)}
{d.products[vatRate=20].vatAmount:aggSum:formatN(2)}
{d.products[vatRate=20].priceGross:aggSum:formatN(2)}

Repeat the row with vatRate=5.5 for the reduced rate, and sum every product without filter for the total row: {d.products[].priceGross:aggSum:formatN(2)}.

5. Apply the Color Theme

The :color formatter applies a color from the JSON data:

  • {d.color:color(p)} in the title paragraph colors its text
  • {d.color:color(row, background)} in a cell of the header row, or of the amount due row, colors the background of the row

For banded rows, place this tag in the loop row:

{d.products[i].sku:print(.i):mod(2):ifEQ(0):show(d.colorLight):elseShow(#ffffff):color(row, background)}
  • :print(.i) returns the index of the row in the loop
  • :mod(2) returns 0 for even rows and 1 for odd rows
  • :ifEQ(0) selects the light color for even rows, and white for the others

Save the DOCX template, connect it to your JSON data, and let Carbone generate your invoices automatically.

Check out these similar templates to learn more:

Trusted by 800+ paid customers in 40+ countries

Finance
Healthcare
Insurance
Legal
Public
Retail
Energy
Software
Telecom
Dior
Thales
Younited
Danfoss
CMA CGM
Illumina
KparK
Scalingo
French Ministry of the Armed Forces
BMW
Telus
Bestseller
Flagship Biosciences
Insly
Ninox
Sodexo