Invoice Automation
Generate PDF Invoices with Carbone
- Template type document docx simple
- Carbone min. v5.0.0+
- Features bidirectional loop set subtotal color
- Target invoice contract custom custom
Objectives
Generate invoices with the following features:
- Repeat the table header when a page breaks.
- Automatically calculate the total of all products.
- Add a page number at the bottom of each page.
- Apply a dynamic color theme.
Solution
Here’s how to construct a template to achieve this with Carbone:
Pagination
Insert Carbone tags as appropriately as possible. Manage the font and formatting to organize your information as desired.
Example :
{d.company.name}
{d.company.address}
{d.company.postalCode} {d.company.city}
Insert a placeholder image for your logo, and set its URL using the View Alt Text option.
Main Table
Insert a table to display your products and references (e.g., prices, quantities, etc.) in columns. If certain values are not stored in your data, you can calculate them—for example, compute a subtotal by multiplying the product price by the quantity, with the formatter
:mul()
Add a row to specify the iteration with the formula :
{d.products[i+1]}
Note: In the table properties, set the text wrapping to None. Uncheck Allow row to break across pages to maintain consistency.
Repeat Table Header on Page Break
Highlight the first line of your main array, right-click, and open the Table Properties menu. Navigate to the Row tab and check the option Repeat as header row at the top of each page.
Calculate the Total of All Products
Add another table to display your invoice total. Use the appropriate formatter :aggSum to compute the sum of all values, and apply the currency formatter :formatC to present the result.
Example:
{d.products[].priceTotal:aggSum:formatC}
Add Page Numbers
Click on Insert > page number in the footer of the template.
Apply a Dynamic Color Theme
Use the following formula to change the text color of a paragraph (e.g., the title of your invoice):
{d.color:color(p)}
Use the following formula to change the background color of a row (e.g., the first row of the main table):
{d.color:color(row, background)}
And there you go!
You might also like
Trusted by 600+ paid customers in 40+ countries














