---
source: https://carbone.io/examples/html-report/
title: "PDF Generation API: HTML to PDF Invoice from JSON | Carbone"
description: "PDF generation API example: fill an HTML and CSS invoice template with JSON data, repeat the item rows, compute the total and get a PDF rendered by Chromium."
generated_at: "2026-11-17"
---

# HTML invoice to PDF

A web page design filled with order data, rendered by Chromium

[![HTML invoice to PDF: PDF generated from an HTML template and JSON data](/examples/html-report/thumb-result.webp)](/examples/html-report/result.pdf "Download the generated document")

[Download template](/examples/html-report/template.md)

[Sample data](/examples/html-report/data.json)

[Download the generated PDF](/examples/html-report/result.pdf)

- **Template:** HTML
- **Export as:** PDF, HTML, PNG, WebP [+7 more](/documentation/developer/http-api/generate-reports.md#output-file-type)
- **Carbone:** 5.4+

Features

-   [HTML](/documentation/design/advanced-features/html.md)
-   [Loop](/documentation/design/repetitions/with-arrays.md)
-   [Aggregation](/documentation/design/computation/aggregation.md)
-   [Currency](/documentation/design/formatters/currency.md)
-   [Image](/documentation/design/advanced-features/pictures.md)

## Generate PDFs from your HTML templates

Web apps, billing systems and e-commerce platforms often already have their documents in HTML and CSS, from a web page or an email design. Your application sends the data to the Carbone API as JSON, the HTML template is filled in, and Chromium converts it to a PDF that looks exactly like the page in a browser. Here, an invoice designed in HTML and CSS is filled with JSON data, then converted to PDF.

In this example, you will:

-   Insert Carbone tags in an HTML template styled with CSS
-   Repeat a table row for each item and compute the total
-   Force the Chromium converter from the template

## How to turn an HTML template into a PDF

Follow these steps to turn an HTML page into a PDF document with Carbone:

### 1\. Lay Out the Invoice in HTML and CSS

In a code editor, create a standard HTML document with `<html>`, `<head>` and `<body>` tags. Define the layout and typography in a `<style>` block of the `<head>`, then build the invoice with HTML tables: header with the logo and the invoice details, addresses, payment method and items.

### 2\. Insert the Data

Insert [Carbone tags](/documentation/design/substitutions/the-basics.md) wherever your data should appear, for example `{d.invoiceNumber}` for the invoice number. Tags also work inside HTML attributes, for example `<img src="{d.companyLogo}">` for the logo.

### 3\. Repeat a Row per Item

In the items table, display each item in a [loop](/documentation/design/template-formats/html.md#loops): the first row contains the tags of the item, the second row marks the end of the loop and does not appear in the generated document.

```html
<tr class="item">
    <td>{d.items[i].name}</td>
    <td>{d.items[i].price:formatC}</td>
</tr>
<tr class="item">
    <td>{d.items[i+1]}</td>
</tr>
```

Below the items, compute the total with the [:aggSum](/documentation/design/computation/aggregation.md#learn-with-aggsum-partitionby) formatter: `{d.items[].price:aggSum:formatC}`.

_Note: the `formatC` formatter displays the amounts in the currency of the report language, for example `$500.00` in `en-us`._

### 4\. Convert the HTML to PDF

To get a PDF that looks exactly like the page in a browser, convert the HTML with Chromium. Add the [in-template option](/documentation/design/overview/in-template-options.md) `{o.converter=C}` anywhere in the `<body>`: Carbone then always uses Chromium for this template, and removes the tag from the result.

Save the HTML template, connect it to your JSON data, and let Carbone turn your web page into a PDF automatically.

## Related Examples

Check out these similar templates to learn more:

- [HTML annual report](/examples/s-annual-report-html/index.md): HTML template to PDF.
- [Multi-page product invoice](/examples/invoice-simple/index.md): DOCX template to PDF.

## Related topics

- [Monthly fund factsheet](/examples/fund-factsheet/index.md)
- [Solar quote with datasheets](/examples/quote-with-datasheet/index.md)
- [Bank statement with page subtotals](/examples/bank-statement-simple/index.md)
- [Checking account statement](/examples/bank-statement-expert/index.md)
- [Usage-based SaaS invoice](/examples/usage-based-billing-invoice/index.md)
- [Utility invoice with payment slip](/examples/invoice-expert/index.md)
