# Convert an HTML invoice to PDF in C#

> Turn an HTML and CSS invoice into a PDF in .NET with page numbers in the margin, without a browser or Chromium. MIT licensed, pure C#.

Available since 1.1.

Render an invoice written in HTML and CSS to a PDF, with a page footer.

## Short answer

Pass the HTML to `HtmlConverter.ConvertToPdf` from the `PdfNetStack.Html` package. The `@page` rule
sets the paper size and margins, and its `@bottom-center` margin box numbers the pages. No browser
runs, and nothing is fetched from the network.

```csharp title="recipe-html-invoice-to-pdf.cs"
#:package PdfNetStack.Html@1.2.0
using PdfNetStack.Html;

string html = """
    <html lang="en">
    <head>
      <title>Invoice 42</title>
      <style>
        @page { size: A4; margin: 2cm; @bottom-center { content: "Page " counter(page) " of " counter(pages) } }
        body { font-family: sans-serif; font-size: 10pt }
        table { width: 100%; border-collapse: collapse }
        th, td { padding: 6pt; border-bottom: 1px solid #CBD5E1; text-align: left }
        td.amount, th.amount { text-align: right }
        tfoot td { font-weight: bold }
      </style>
    </head>
    <body>
      <h1>Invoice 42</h1>
      <p>Issued 2026-10-29. Payment due within 30 days.</p>
      <table>
        <thead><tr><th>Item</th><th class="amount">Amount</th></tr></thead>
        <tbody>
          <tr><td>Consulting, 8 hours</td><td class="amount">800.00 EUR</td></tr>
          <tr><td>Support plan</td><td class="amount">200.00 EUR</td></tr>
        </tbody>
        <tfoot><tr><td>Total</td><td class="amount">1,000.00 EUR</td></tr></tfoot>
      </table>
    </body>
    </html>
    """;

byte[] pdf = HtmlConverter.ConvertToPdf(html);
File.WriteAllBytes("invoice-42.pdf", pdf);
```

## Variations

- `HtmlConverter.ConvertFileToDocument("invoice.html")` reads a file, and its style sheets, images
  and fonts from the same folder.
- `ConvertToDocument` returns a `PdfDocument`, so the invoice can be signed, encrypted or saved as
  PDF/A before it is written.
- Fonts declared with `@font-face` are embedded. The generic families `serif`, `sans-serif` and
  `monospace` map to the standard PDF fonts, which need no embedding.

## Related

- [HTML to PDF](https://www.jadev-corp.com/guides/html-to-pdf/)
- [Create a Factur-X invoice](https://www.jadev-corp.com/recipes/pdf-a-3-xml-attachment/)
- API: [HtmlConverter](https://www.jadev-corp.com/api/pdfnetstack-html/htmlconverter/), [HtmlConverterOptions](https://www.jadev-corp.com/api/pdfnetstack-html/htmlconverteroptions/)

Source: https://www.jadev-corp.com/pdfnetstack/recipes/html-invoice-to-pdf/
