For existing HTML, a practical free route in C# is Microsoft Playwright for .NET with Chromium: load the HTML or navigate to a page, then call Page.PdfAsync. The important trade-off is deployment: your app needs Playwright’s browser binaries and, on some Linux hosts, system dependencies. PDF generation also uses print styles by default, so check the output against the styles and page breaks you expect.
Use Playwright when the input is already HTML
Playwright controls a browser engine, which means it can render a page from a URL or an HTML string and export the rendered page as a PDF. That makes it a better fit for HTML you already have than a PDF library whose input is a document layout you must build in C#.
The package is Microsoft.Playwright. Microsoft’s .NET port supports the Playwright browser automation API; its installation documentation describes installing the package and browser binaries and lists supported operating systems. Check that support information against the runtime and operating system you deploy to before shipping.
The code below follows the documented Playwright .NET API shape. It illustrates the conversion flow; it is not a tested production sample. In a real app, add application-specific error handling, logging, and resource cleanup.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Convert a URL or an HTML string
Install the Microsoft.Playwright NuGet package in your project, then use one of these input approaches. The browser launch, page creation, and PDF export are shared.
Complete minimal example for a URL
using Microsoft.Playwright;
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync("https://example.com");
await page.PdfAsync(new() { Path = "output.pdf" });
Put this in an async entry point or an async method called by your application. GotoAsync navigates to the address; PdfAsync writes the PDF at the supplied path. Ensure the process has permission to write there, and use a path appropriate to your deployment rather than assuming the working directory is writable.
Render HTML you already have
Replace navigation with SetContentAsync when the HTML is already available as a string:
using Microsoft.Playwright;
var html = "<!doctype html><html><body><h1>Invoice</h1><p>Example</p></body></html>";
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.SetContentAsync(html);
await page.PdfAsync(new() { Path = "output.pdf" });
For a document that refers to images, stylesheets, or fonts, check how those assets are addressed and whether the browser can load them in the target environment. A self-contained HTML string does not automatically make external resources available.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #2
Install the browser on the machine that runs the app
Adding the NuGet package alone is not the whole deployment. Playwright needs its browser binaries on the host that executes the conversion. Install the package and use the Playwright-generated install script to install Chromium for the target environment. On Linux, install the system dependencies where required. Follow the current Playwright .NET installation instructions for the supported operating system and runtime; do not assume that a browser installed on a developer workstation will also be present in a container or production host.
For ASP.NET applications, the conversion code can run in a server-side service or endpoint, but the same host requirements apply. Choose an output location the process can write to, and decide how the resulting file is returned or stored. Browser installation and PDF rendering are deployment concerns as well as code concerns.
Control print and screen styling
Page.PdfAsync renders using print CSS media by default. If the document should use its screen styles instead, select screen media through Playwright’s media-emulation API before exporting. This choice can change layouts substantially: sites often hide navigation, change colors, or rearrange content under print rules.
PDF output also adjusts colors for printing by default. If color accuracy matters, use the CSS property -webkit-print-color-adjust and inspect the resulting PDF in the target environment. Do not assume that setting a CSS property alone guarantees an exact match across documents or environments.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Before relying on a template, review representative output for:
- Page breaks, clipped content, headers, and footers.
- Fonts and other external assets that may load differently on the deployment host.
- JavaScript-rendered content and whether it is present by the time the PDF is generated.
- Differences between print and screen styles, including background colors.
Choose HTML rendering or a C# PDF layout library
These tools solve related but different problems. Playwright renders existing HTML in a browser. QuestPDF is a PDF document-generation library with a fluent C# layout API; it is relevant when you can compose the document structure in C#, rather than when you need a drop-in converter for existing HTML.
| Consideration | Playwright for .NET | QuestPDF |
|---|---|---|
| Input model | Existing HTML, set as content or reached by navigation; browser renders it before PDF export. | Document structure composed with a C# layout API; not a direct existing-HTML converter. |
| Runtime footprint | Requires Playwright browser binaries on the execution host and may require Linux system dependencies. | Uses a PDF layout approach rather than launching Chromium for HTML rendering. |
| Styling approach | Uses page styling, with print CSS as the PDF default; screen media can be selected explicitly. | Layout is defined through its own API rather than by rendering existing HTML. |
| License point to verify | Confirm applicable package and deployment terms for your use. | The official Community License guide, version 3.0 effective 6 July 2026, calls it source-available, not OSI-approved open source, and sets eligibility conditions. |
QuestPDF’s official license guide says: “This is a source-available commercial license. It is not an OSI-approved open-source license, and the MIT License does not govern use of the Software under this Community License.” Check the current license terms and your organization’s eligibility before adopting it, particularly for commercial use. A library being available without an upfront charge does not by itself establish that it is free for every organization or use.
IronPDF is another named commercial .NET HTML-to-PDF option. Check its current vendor terms if you consider it; current pricing and licensing details are not established here.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesRank #4
Or skip the browser setup
If you need a hosted screenshot or PDF from a URL rather than a PDF generated from an HTML string already in your C# process, ScreenshotNeo offers a one-request API. It is not a drop-in substitute for Playwright’s SetContentAsync flow: the example below captures a URL.
cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options and response details. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common conversion problems
The app cannot launch Chromium
The browser may not be installed in the environment running the app, or the host may lack required system dependencies. Install the Playwright browser binaries for that target and, on Linux where needed, the system dependencies. Verify the deployment OS against Playwright’s current supported-platform information.
The PDF looks unlike the page in a browser
First check media mode. PDF uses print CSS by default; select screen media if that is the intended design. Then inspect print-specific CSS, page breaks, fonts, and loaded assets. Browser rendering support does not prove every page will match a particular screenshot or layout exactly.
Content or images are missing
Check whether the relevant content depends on JavaScript or external assets and whether those resources are available to the browser on the host. If the page’s content appears after navigation, ensure the application’s conversion flow waits for the content it needs before calling PdfAsync. Validate with representative pages rather than assuming all pages load alike.
Best Value
The PDF has unexpected colors
Print output adjusts colors by default. If accurate colors are required, apply -webkit-print-color-adjust where appropriate and inspect the generated file. Also verify whether print media is applying different colors from screen media.
The output file is absent or cannot be saved
Check that the path passed to PdfAsync points to a location that exists or can be created and that the application process has write permission. In a server deployment, do not assume the local working directory is a persistent or writable storage location.
Plan for reliability, performance, and cost
Playwright gives you a browser-backed rendering path, but the official API and installation information do not establish a universal conversion speed, throughput, or pixel-perfect fidelity. Measure your own representative documents and deployment environment before setting capacity expectations. Include the browser installation, OS dependencies, and output storage in your operational plan.
For repeatable output, keep a small set of sample documents covering long pages, tables, images, custom fonts, and print-specific styles. Compare the resulting PDFs after changes to templates, browser binaries, or host configuration. This is more useful than assuming one successful simple page proves all production documents will render correctly.
Frequently asked questions
Can I use this approach in an ASP.NET application?
Yes. The rendering flow can be called from server-side application code. The server still needs the Playwright browser binaries and any platform dependencies, plus a deliberate strategy for saving or returning the PDF.
Does Page.PdfAsync guarantee pixel-perfect output?
No universal fidelity guarantee is established by API support alone. Render and inspect the specific templates, styles, assets, and deployment environment you intend to use.
Is QuestPDF an HTML-to-PDF replacement?
Not for the same input model: QuestPDF defines document layouts in C#. Use it when composing a document through its layout API is suitable, and use a browser-backed approach when the source is existing HTML.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




