Ask how to turn HTML into a PDF in C# and you get a list of library names. What you rarely get is the same document run through each of them, so you can see what comes out. So we did that: one invoice, four open-source .NET libraries, each set up the way its own documentation describes, on the kind of Linux machine these things end up running on.
Disclosure: I'm on the team behind Dynamic Document API, a hosted HTML to PDF API, so we have a horse in this race. That's why everything below is in a public repository and runs in GitHub Actions: the code, the PDFs and the run log. Commercial libraries aren't part of the test.
The test document
Nothing exotic, just what a real invoice uses today:
- a header laid out with Flexbox, with an inline SVG logo
- the invoice details (number, dates, PO) in a two-column CSS grid
- a web font (Inter, loaded with
@font-face) - 36 line items, so the table runs onto page 2 and should repeat its header row there
- totals that shouldn't be split across pages
- US Letter, and a footer with the seller on the left and "Page 1 of 2" on the right
Every library got the same HTML, rendered beforehand from a Razor component; only the page setup (size, margins, page numbers) was added the way each library wants it. The run used .NET 10.0.15 on the ubuntu-24.04 GitHub runner (Ubuntu 24.04.5 LTS).
The results
Page 1 from each library:

PuppeteerSharp 25.18.1 with Chrome 157: as designed.

iText pdfHTML 6.3.4: almost there. The grid is stacked.

HtmlRenderer.PdfSharp 1.6.1: header, addresses, table header and totals are gone.

DinkToPdf 1.0.8 with wkhtmltopdf 0.12.6.1: Flexbox and grid ignored.
| PuppeteerSharp | iText pdfHTML | HtmlRenderer.PdfSharp | DinkToPdf | |
|---|---|---|---|---|
| Engine | Chrome | its own | its own, on PDFsharp | wkhtmltopdf (Qt WebKit) |
| Flexbox | ✅ | ✅ | ❌ box not drawn | ❌ ignored |
| CSS grid | ✅ | ❌ stacked | ❌ box not drawn | ❌ ignored |
| Web font | ✅ | ✅ | ❌ fallback font | ✅ |
| Table header on page 2 | ✅ | ✅ | ❌ no header row at all | ✅ |
| Page numbers | footer template | CSS @page | draw them yourself | footer settings |
| Runs JavaScript | ✅ | ❌ | ❌ | ✅ (old WebKit) |
| License | MIT | AGPL-3.0 or commercial | BSD-3-Clause | MIT (wkhtmltopdf: LGPL-3.0) |
| Latest release | Nov 2026 | Sep 2026 | Jul 2026 | Apr 2017 |
The JavaScript row comes from a second test page with one <script> that changes a word on the page.
Now the parts that don't fit in a table.
PuppeteerSharp: right result, but you're running Chrome
PuppeteerSharp drives a real headless Chrome, so the PDF is what Chrome's print preview shows you. That's the whole appeal, and it delivered.
The cost shows up in operations:
- The download.
BrowserFetcherpulled Chrome plus its headless shell: 716 MB on disk. Put it into your Docker image or onto the server at deploy time, not at the first request. - "No usable sandbox!" Our first CI run died with this. Ubuntu 23.10 and later use AppArmor to restrict the unprivileged user namespaces that Chrome's sandbox needs. The quick fix many answers give is
--no-sandbox. We didn't want that, so the workflow allows the namespaces instead:
- name: Allow Chrome's sandbox run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 On a disposable CI runner that's fine. On your own servers, an AppArmor profile for the Chrome binary is the narrower fix, because it doesn't lift the restriction for everything else too.
- The footer is its own little page.
FooterTemplatedoesn't see your document's CSS, so it needs inline styles and its own margins. Chrome fills in the page numbers through two class names:
FooterTemplate = """<div style="font-size: 7pt; width: 100%; margin: 0 16mm; display: flex; justify-content: space-between">""" + """<span>Northwind Outdoor Supply</span>""" + """<span>Page <span class="pageNumber"></span> of <span class="totalPages"></span></span></div>""", And then there's everything that comes with running a browser in production: memory per page, a timeout for pages that never finish loading, and Chrome security updates every few weeks.
iText pdfHTML: the best of the browser-free options
iText's HTML add-on got further than I expected: Flexbox, the web font, the repeated table header and CSS paged media all worked. Page numbers go through @page margin boxes, which is the standard way and very readable:
@page { size: Letter; margin: 16mm 16mm 20mm 16mm; @bottom-right { content: "Page " counter(page) " of " counter(pages); font-family: Helvetica, sans-serif; font-size: 7pt; } } Two things to know:
- CSS grid isn't supported. The two-column details block came out as one column. If your templates use grid, rewrite those parts with Flexbox or a table.
- Fonts in margin boxes. With
font-family: Arial, sans-serif, the footer came out in Times-Roman. Out of the box iText knows the standard PDF fonts, not the system's Arial. Use Helvetica, or give the converter a font provider with your own fonts.
No JavaScript, so charts and anything else drawn by a script won't appear. And look at the license before you ship: it's the AGPL-3.0 or a commercial license, and the AGPL has its own rules for software that users reach over a network.
HtmlRenderer.PdfSharp: fast, until half the page quietly disappears
This one was the fastest in our run, 0.24 seconds for both pages. Part of the reason: it left out a lot. The logo, the invoice details, both addresses, the table's header row and the totals were simply not there. There was no exception and no warning; the PDF just started with line item 1.
To find out why, we cut the stylesheet down piece by piece. Remove display: flex and display: grid, and the content comes back. HtmlRenderer's own layout engine covers older CSS, and a box it can't lay out isn't drawn at all, its content included. It also didn't use the web font; on the Linux runner it fell back to a font called Tuffy.
There's no header or footer support either, so page numbers are drawn onto each page with PDFsharp afterwards:
var font = new XFont("Arial", 7); for (var i = 0; i < document.PageCount; i++) { var page = document.Pages[i]; using var graphics = XGraphics.FromPdfPage(page); var line = new XRect(45, page.Height.Point - 34, page.Width.Point - 90, 10); graphics.DrawString($"Page {i + 1} of {document.PageCount}", font, XBrushes.Black, line, XStringFormats.CenterRight); } It's small, permissively licensed and has no native dependencies. For simple documents built from tables and blocks, that's a good deal. Just render your real templates with it and compare the result with what you expect, because when something is missing, it won't tell you.
DinkToPdf: works, but frozen in time
DinkToPdf is a .NET wrapper around wkhtmltopdf's native library. Its last release is from April 2017, and wkhtmltopdf itself has been archived since January 2023. Its Qt WebKit is older than Flexbox and grid as we use them today, so both were ignored and the layout fell back to stacked blocks. The web font, the repeated table header and the page numbers ([page] and [topage] in FooterSettings) worked, and it even runs JavaScript, with an old engine.
Two practical notes if you maintain an app that uses it:
- You deploy the native library yourself, for every platform. On Ubuntu 24.04 we installed the 0.12.6.1 package built for 22.04 (jammy), which worked.
- wkhtmltopdf can be loaded only once per process. Create one
SynchronizedConverterfor the whole app, as a singleton, not one per request.
For a new project, I wouldn't start here. If you're moving away from it, we wrote up what breaks in wkhtmltopdf and what to replace it with.
So which one?
- It has to look like it does in Chrome: PuppeteerSharp, and plan for running Chrome (image size, sandbox, memory, updates).
- No browser, no JavaScript needed, and the license fits: iText pdfHTML. Avoid CSS grid.
- Simple layouts and a permissive license: HtmlRenderer.PdfSharp, after checking that nothing goes missing.
- New project: not DinkToPdf.
- Chrome's result without running Chrome: that's what a hosted API is for, and it's what we build. The full tutorial renders this same invoice through ours with plain
HttpClient: from a template, from a Razor component, and from an ASP.NET Core endpoint with retries. Your HTML and data are sent to us, so check whether that works for your project.
Run it yourself
Everything is in DynamicDocumentApi/html-to-pdf-csharp: the invoice, the four renderers in Renderers.cs, the workflow and the PDFs. The comparison needs no API key:
dotnet run --project compare/Compare -c Release If you'd configure one of the libraries differently, or know a setting that fixes one of these results, open an issue or a pull request. I'll rerun it and update the results.
