Generating PDFs in .NET is often painful—low-level drawing APIs, rigid libraries, and pricey licenses all get in the way.
Playwright flips the script: design with plain HTML and CSS, then export directly to PDF. This walkthrough shows how to load a template, replace placeholders at runtime, and generate a styled PDF with Playwright in .NET.
Generating a nicely formatted PDF is surprisingly hard with traditional .NET libraries.
Pixel‑perfect layout often requires low‑level drawing APIs or proprietary tooling.
When looking for a solution, I stumbled upon
Microsoft Playwright, a library for end-to-end testing in the browser.
This in itself might not sound like a good fit for PDF generation,
but if you know that the print preview inside a Chromium browser is actually a rendered PDF, it makes more sense.
So if we can render HTML in a browser, we can also export it to PDF.
And this gives us all the flexibility of HTML and CSS for layout,
without the hassle of low-level drawing APIs.
read more…