html4pdf vs wkhtmltopdf

For a decade wkhtmltopdf was the default answer in every language, usually through a wrapper: WickedPDF, pdfkit, DinkToPdf, Browsershot's predecessor. Then the web moved and it did not.

The short answer

wkhtmltopdf is still fine for simple documents you already have working. For anything new, or anything using modern CSS, its archived WebKit engine is the problem you will eventually hit.

What wkhtmltopdf is

wkhtmltopdf is a command line tool that renders HTML to PDF using an old fork of QtWebKit. It is a single binary, it needs no runtime, and it is genuinely fast. Development has stopped and the project is archived, so the rendering engine is frozen at a point in web history before flexbox and grid were usable.

Side by side

 wkhtmltopdfhtml4pdf
Rendering engineA fork of QtWebKit, frozenCurrent headless Chrome
Flexbox and gridNot supported, layouts fall back to blocksSupported
JavaScriptOld engine, unreliable for modern scriptsFull support, scripts run before capture
Web fontsPatchyGoogle Fonts and @font-face work
MaintenanceArchived, no security updatesChrome, updated continuously
InstallationA native binary per platform, per architectureNone
SpeedVery fast, no browser to startThree to five seconds including the round trip
CostFreeFrom $0.033 per document
Headers and footersBuilt in, via command line flagsVia page options, or CSS

Choose wkhtmltopdf when

  • You have documents that already render correctly and nobody is redesigning them.
  • You need sub-second rendering and your layout is plain CSS.
  • The work must stay entirely offline, with no outbound network call.
  • Cost per document has to be zero.

Choose html4pdf when

  • Your design uses flexbox, grid, or a web font, and the PDF no longer matches the page.
  • You are tired of shipping a platform-specific binary in your image.
  • An archived dependency with no security updates is becoming a compliance conversation.
  • You are starting something new and would rather not inherit the problem.

See the code

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

wkhtmltopdf: common questions

Is wkhtmltopdf deprecated?

The project is archived and no longer developed. It still runs, and many systems still depend on it, but there are no fixes coming, including security fixes in the bundled engine.

Why does flexbox not work in wkhtmltopdf?

Its engine is an old fork of QtWebKit that predates usable flexbox support. The properties are ignored, so the layout falls back to normal block flow, which is why a two column design arrives stacked.

What should I replace wkhtmltopdf with?

Something based on a current browser. Run it yourself with Puppeteer, Playwright or chromedp, or call an API that runs one. If your documents are simple and you want pure Python, WeasyPrint is also a reasonable landing spot.

Will my existing HTML work without changes?

Usually it will look better, because Chrome supports more than the old engine did. Watch for layouts that were built around wkhtmltopdf quirks, and for its command line header and footer flags, which become CSS or page options.

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