html4pdf vs Playwright

Most teams meet Playwright in their test suite and then notice page.pdf() exists. It works. The surprise is how different a browser in CI feels from a browser in production.

The short answer

Playwright is the better browser automation library. It is not a better PDF pipeline, because the cost was never the library: it is operating the browser. Use it if you already run it, call an API if you do not.

What Playwright is

Playwright is Microsoft's browser automation library, available for Node, Python, Java and .NET. It drives Chromium, Firefox and WebKit, with better waiting, tracing and debugging than Puppeteer. PDF output is Chromium only, because the other two engines do not expose it.

Side by side

 Playwrighthtml4pdf
Rendering engineChromiumHeadless Chrome
LanguagesNode, Python, Java, .NETAny language with HTTP
What you deployYour app plus browser binariesNothing
Install sizeHundreds of megabytes per browserNone
In CIExcellent, this is what it is forWorks, but you are paying per document in tests
In productionA long-running browser to supervise, restart and capAn HTTPS call
Beyond PDFsTesting, scraping, screenshots, tracingDocuments only
Cost per documentYour own computeFrom $0.033

Choose Playwright when

  • Playwright is already in your stack and you have somewhere to run it.
  • You need to interact with the page before printing: log in, click through, wait for a condition.
  • You want screenshots and traces from the same tool.
  • Volume is high enough that per-document pricing is the larger cost.

Choose html4pdf when

  • The only thing you need from a browser is a PDF.
  • Your production environment is serverless, or a container you would rather keep small.
  • You write in a language Playwright does not support, or do not want the dependency.
  • You would rather not be the person who understands why the browser pool wedged.

See the code

The working example, in the language this decision is being made in.

Playwright: common questions

Can Playwright generate PDFs?

Yes, with page.pdf() in Chromium. Firefox and WebKit do not support it, so the multi-browser advantage does not apply to PDF output.

Playwright or Puppeteer for PDFs?

Playwright, if you are choosing between running one of them yourself. Better API, better waiting, better debugging, and the same Chromium underneath.

Is Playwright hard to run in production?

Harder than in CI. A test run starts a browser and throws it away; a service keeps one alive under load, which means memory caps, restarts and a plan for when a render hangs.

Can I use Playwright in a serverless function?

With difficulty. The browser binaries are large and cold starts are slow, which is why most teams end up running a separate container for it.

Try it before you decide

New accounts get 10 free credits, no card. Send the HTML you already have and compare the output against whatever you are using now.

Get API key

Other comparisons