HTML to PDF in C#: PdfSharp, QuestPDF, iText, Puppeteer or an API
Published 4 min read
The first decision in C# is not which library to install, but which kind of tool you want. They differ in what you write (code, HTML or a layout), where the work happens (inside your process, in a browser you ship, or on someone else’s server) and what you have to keep up to date. This guide sorts the options by kind. We make one of them, the API, so we say plainly where it is not the right answer.
Libraries change their features and licenses. Read the current documentation and license of anything you consider; what follows describes the approach of each, not the fine print.
Six approaches
| Approach | Examples | You write | Watch for |
|---|---|---|---|
| Draw from code | PdfSharp, MigraDoc | Drawing at positions you choose (PdfSharp) or a document model with flowing text and tables (MigraDoc), all in C#. | No HTML conversion of its own: HTML has to be turned into this model by you or by an add-on. |
| A layout in C# | QuestPDF | A fluent C# description of the document, with a real layout engine. | Not HTML. Its license depends on the size and kind of your company: read the current terms. |
| HTML through a library | iText with its HTML add-on, packages built on HtmlRenderer | HTML and CSS, converted in your process. | iText is dual-licensed (open source AGPL or commercial). HtmlRenderer targets HTML 4.01 and CSS 2, so modern layout such as flexbox is not what it is for. |
| A browser you run | PuppeteerSharp, Playwright | HTML, CSS and JavaScript, rendered by Chromium. | You download and keep up to date a browser, with its memory, start-up time and sandbox. |
| An old converter | wkhtmltopdf and its wrappers (DinkToPdf, Rotativa) | HTML and CSS. | The upstream project is archived: no more fixes. Its own documentation warns against untrusted HTML. |
| An HTTP API | rustedf.cloud | HTML and CSS, or a saved template, sent with HttpClient. |
Your data leaves your server. It needs the network, and your plan sets the limits. |
How to choose
Ask these questions in order. The first honest “yes” usually decides it.
Does the page need JavaScript to exist? A single-page app, a chart drawn in the browser, a page that builds itself on load. Only a browser renders that. PuppeteerSharp or Playwright are the answer, and the API is not.
Is the document built in C# and has no HTML? Invoices assembled from objects, labels, tickets. A layout library such as QuestPDF or a drawing library such as PdfSharp fits, and they need no network.
Can the data leave your server? If a regulation or a contract says it cannot, use something that runs in your process or in a browser you host. An API call sends the document’s data to a service.
Do you already have HTML? A Razor view, an email template, a page built for printing. Then the choice is between a browser and the API. The browser has the full set of web features and costs you its upkeep. The API has none of the upkeep and supports the parts of HTML and CSS that matter for paper: pages, tables that continue across pages, headers and footers.
Where does it run? In a container or a serverless function, a Chromium adds to the image and to the cold start. An HTTP call adds nothing to either.
What the API version looks like
using var response = await http.PostAsJsonAsync( "v1/render", new { html, title = "Invoice 2026-0042" }, cancellationToken);response.EnsureSuccessStatusCode();byte[] pdf = await response.Content.ReadAsByteArrayAsync(cancellationToken);There is no package to install and no native file to ship. The cost is the list of what it does
not do: no JavaScript, no @font-face or @import, and images only as data: URLs or files you
upload. Send the same body to POST /v1/validate first: it tells you what the service could not
use, with no PDF and no credit.
Where to go next
- A typed client, retries and the errors to handle: Generate a PDF from HTML in C# and ASP.NET Core.
- Pages that already exist on the web: Convert a web page to PDF in C# without a headless browser.
- A table that spans pages, with totals and page numbers: C# PDF report generator.
Read Supported HTML and CSS before you decide: it lists exactly what the renderer supports.
Keep reading
Code and integrations
Generate a PDF in ASP.NET Core: MVC, Razor Pages and minimal APIs
Turn a Razor view into a PDF in ASP.NET Core with one API call: a view renderer, a print-ready view, an MVC action, a Razor Pages handler and the traps to avoid.
3 min read
Code and integrations
Convert a web page to PDF in C# without a headless browser
Fetch a page with HttpClient and turn its HTML into a PDF with one API call in C#. Which pages this suits, which it does not, and how to check before you rely on it.
3 min read
Code and integrations
C# PDF report generator: a paged table with totals and page numbers
Build a PDF report in C# from a list of objects: a table whose header repeats on every page, a total, page numbers and the page count, with one HTTP call.
3 min read
Code and integrations
Save a PDF in C#: to disk, as a download or in blob storage
Save the PDF returned by a render call in C#: write it to disk, send it as a download from ASP.NET Core, keep a signed link or upload it, and avoid saving an error.
2 min read