wkhtmltopdf alternative for Python
For Python, replace the archived wkhtmltopdf binary with Playwright's Chromium: page.pdf() prints the same HTML with modern CSS and web fonts loaded. Most pdfkit options map one to one onto the print call, and the smart-shrinking workarounds in tuned templates have nothing left to compensate for.
pdfkit and weasyprint users feel this first: pdfkit shells out to the dead binary; weasyprint never ran JavaScript at all.
Install
pip install playwright, then playwright install chromium. Both run inside your project's virtualenv; no system package and no binary on PATH.
What you keep: pdfkit options become Playwright arguments
The pdfkit mapping is line for line. Page size becomes format, orientation becomes landscape, margins become the margin object, zoom becomes scale, and --print-background becomes print_background=True. The flag-by-flag table on the wkhtmltopdf alternatives hub applies to Python unchanged.
What actually changes
pdfkit never rendered anything: it exec'd the binary, so the wkhtmltopdf system package was load-bearing in every virtualenv, container, and CI image. Playwright inverts that: playwright install pins the browser next to your pip dependencies, so the render engine's version is a project concern, not a machine concern. The font installs and the smart-shrinking flags the binary demanded have no counterpart to migrate.
Before and after on a typical pdfkit call:
Before, pdfkit shelling out to the archived binary:
import pdfkit
pdfkit.from_url("https://example.com/report", "out.pdf",
options={"disable-smart-shrinking": "", "print-background": ""})
After, Playwright printing with Chromium:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://example.com/report", wait_until="networkidle")
page.pdf(path="out.pdf", print_background=True, format="A4")
browser.close()
Two settings do most of the repair work here: wait_until="networkidle" waits for the page to finish before printing, and print_background=True keeps background colors and images. Everything else maps from the pdfkit options it replaces.
Verify before you cut over
Before you cut over, run your worst legacy template through the after snippet above and put the old wkhtmltopdf output beside it. Compare page count, fonts, backgrounds, and page breaks: most differences are the deleted smart-shrink workarounds, and the few that remain are real layout changes from the newer engine.
WeasyPrint or Chromium?
WeasyPrint wins for documents authored for print: pure Python, strong paged-media CSS, no browser to run. It cannot execute JavaScript, so anything client-rendered must use Chromium.
Frequently asked questions
Does pdfkit still work?
It runs, but through the archived binary: pdfkit is a thin subprocess around wkhtmltopdf, so every render inherits the 2023 freeze and no fix will ever arrive. Working today is not the same as safe to depend on.
Do I have to rewrite my pdfkit options?
Rename them, mostly: format, landscape, margin, scale, and print_background each become one argument of page.pdf(). The hub's flag table covers the stragglers that map to page and context calls instead.
Method
Checked 2026-09-11 against the pdfkit option reference and the current Playwright for Python print documentation.
More languages: the PHP migration guide, the C# migration guide, the Java migration guide, the Go migration guide. The wkhtmltopdf alternatives hub holds the full flag table and the honest before-and-after notes.
Going deeper: the Gotenberg vs WeasyPrint head-to-head covers the same print-engine-versus-browser question, the open-source comparison prices the free routes against hosted ones, and the webcapture product page states the hosted engine, pricing, and a curl quick start.
Render your first page in seconds
Mint a key, POST a URL, and the finished document comes back in the same response; pass ?wait=false for a job ticket with poll and download URLs. The first 50 renders a month are free, and there is no credit card. Not ready for a key? The free URL to PDF tool renders public pages without one.