wkhtmltopdf alternatives: what to use instead
By Mayur Gadakh · Published · Last updated
wkhtmltopdf is no longer maintained: its GitHub repository was archived on January 2, 2023, the last release (0.12.6) came out in June 2020, and its maintainer notes that the WebKit inside it has not been updated since 2012. For most projects the replacement is headless Chrome, used from the command line, from code with Puppeteer or Playwright, or as an HTTP service with Gotenberg. If you control the HTML and want print features such as running headers and page counters, WeasyPrint (free) and Prince (commercial) are built for paged layout. The Chrome, Puppeteer, Playwright, WeasyPrint and Gotenberg examples below were run as written on 2026-12-04.
Is wkhtmltopdf still maintained?
No. The wkhtmltopdf repository was archived by its owner on January 2, 2023 and is read-only. The last release, 0.12.6, was published on June 10, 2020; the separate packaging project shipped rebuilt binaries (0.12.6.1-3) in May 2023. The maintainer's status page explains why: wkhtmltopdf is built on QtWebKit, which Qt deprecated in 2015 and removed in 2016, and “Qt 4 (which wkhtmltopdf uses) hasn't been supported since 2015, the WebKit in it hasn't been updated since 2012.”
In practice, a 2012 engine predates CSS Grid and the standard display: flex syntax (flexbox layouts are a long-standing complaint, see issue #1522), JavaScript written for current browsers can fail, and security problems will not be fixed. The status page puts it plainly: “Do not use wkhtmltopdf with any untrusted HTML.”
“If you're using it for report generation (i.e. with HTML you control), also consider using WeasyPrint or the commercial tool Prince … If you're using it to convert a site which uses dynamic JS, consider using puppeteer or one of the many wrappers it has.” — wkhtmltopdf's maintainer, on the status page
Which wkhtmltopdf alternative should I use?
- You render your own templates (invoices, reports): headless Chrome with CSS for paper size and page numbers, or WeasyPrint if you work in Python and want the strongest free CSS paged-media support. Prince if print quality justifies a licence.
- Your pages need JavaScript (charts, single-page apps): a Chrome-based tool: Puppeteer, Playwright or Gotenberg. WeasyPrint does not run scripts, and Prince runs only some, when enabled.
- You call wkhtmltopdf from PHP, Ruby, Python or .NET: swap the wrapper for a Chrome-based library in the same language (see the wrapper table), or run Gotenberg next to your app and call it over HTTP.
- You convert public web pages and do not want to run a browser: a hosted API. URLBooth turns a public URL into a PDF or an image with one request.
wkhtmltopdf alternatives compared
| Tool and engine | Runs JavaScript | Licence and cost | Best for |
|---|---|---|---|
| Headless Chrome (command line) Current Chrome | Yes | Free | Scripts and one-off conversions |
| Puppeteer Chrome, from Node.js | Yes | Free, Apache-2.0 | Node.js apps; its PDF options closely resemble wkhtmltopdf's |
| Playwright Chromium, from Node.js, Python, Java or .NET | Yes | Free, Apache-2.0 | Apps outside Node.js |
| Gotenberg Chromium and LibreOffice in one Docker container | Yes | Free, MIT | Any language over HTTP; also Word and Excel to PDF |
| WeasyPrint Its own layout engine, written in Python | No | Free, BSD-3-Clause | Invoices and reports from HTML you control |
| Prince Its own engine | Mostly ES5, off by default | Free for non-commercial use (logo on page 1); desktop licence $495; server site licence from about $2,000 a year | Books and demanding print layout |
| URLBooth API Chromium, hosted | Yes | Pro plan, $20 a month for 10,000 captures a day | Public URLs to PDF or screenshots, no browser to run |
Prices and licences as of 2026-12-04. Prince's free licence also requires links to princexml.com where the documents are published, and it may not be used for commercial documents. DocRaptor and EuroPDF offer Prince as an online service.
How do I make a PDF with headless Chrome, without code?
Chrome can print any page to PDF from the command line. This writes invoice.pdf to the current folder:
chrome --headless --no-pdf-header-footer --print-to-pdf=invoice.pdf https://example.com
On macOS the binary is "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; on Linux it is usually google-chrome or chromium. --no-pdf-header-footer removes the date, title, URL and page number Chrome otherwise prints in the margins (older versions call it --print-to-pdf-no-header), and --timeout=5000 prints after at most five seconds even if the page is still loading.
There are no flags for paper size, margins or page numbers. Put them in the page's CSS instead: Chrome reads @page rules, and since Chrome 131 it also supports page-margin boxes, which replace wkhtmltopdf's --footer-center "Page [page] of [topage]":
@page {size: A4;margin: 20mm 15mm;@bottom-center {content: "Page " counter(page) " of " counter(pages);font: 9pt sans-serif;}}
With that CSS, Chrome 158 produced an A4 PDF with “Page 1 of 2” and “Page 2 of 2” in the footer, and WeasyPrint 70 rendered the same file with the same footer, so one template works in both.
How do I port a wkhtmltopdf command to Puppeteer?
Take a typical wkhtmltopdf call:
wkhtmltopdf --page-size A4 --margin-top 20mm --margin-bottom 20mm \--footer-center "Page [page] of [topage]" --footer-font-size 9 \https://example.com report.pdf
This Puppeteer script (npm i puppeteer) produces the same document, footer included:
import puppeteer from "puppeteer";const browser = await puppeteer.launch();try {const page = await browser.newPage();// wkhtmltopdf uses screen CSS unless you pass --print-media-type.await page.emulateMediaType("screen");await page.goto("https://example.com", { waitUntil: "networkidle0" });await page.pdf({path: "report.pdf",format: "A4",printBackground: true, // wkhtmltopdf prints backgrounds by defaultmargin: { top: "20mm", right: "10mm", bottom: "20mm", left: "10mm" },displayHeaderFooter: true,headerTemplate: "<span></span>",footerTemplate:'<div style="width:100%;text-align:center;font-size:9px">' +'Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>',});} finally {await browser.close();}
- Two defaults are opposite. wkhtmltopdf renders with screen CSS and prints backgrounds; Chrome uses print CSS and drops backgrounds unless
printBackgroundis true. Without the two marked lines, a page can look different from its wkhtmltopdf version. - Paper size differs too. wkhtmltopdf defaults to A4, Puppeteer to Letter.
- Header and footer templates are separate documents. They do not get the page's stylesheets, so style them inline. The empty
headerTemplatestops Chrome from printing its default header (date and title) when only a footer is wanted. - Wait for content, not for time. Instead of
--javascript-delay, wait for the network to go quiet or for a specific element withpage.waitForSelector().
The Puppeteer PDF guide covers backgrounds, page breaks and container setup in more detail.
How do wkhtmltopdf options map to Puppeteer?
| wkhtmltopdf | Puppeteer | Notes |
|---|---|---|
--page-size A4 | format: "A4" | wkhtmltopdf defaults to A4, Puppeteer to Letter. |
--orientation Landscape | landscape: true | |
--margin-top 20mm (-bottom, -left, -right) | margin: { top: "20mm" } | wkhtmltopdf's left and right margins default to 10mm. |
--page-width, --page-height | width, height | |
--print-media-type | (the default) | Chrome uses print CSS. wkhtmltopdf uses screen CSS unless you pass this flag; to keep that look call page.emulateMediaType("screen"). |
--background (default), --no-background | printBackground: true / false | Puppeteer's default is false. |
--header-html, --footer-html, --footer-center | displayHeaderFooter: true, headerTemplate, footerTemplate | Or CSS page-margin boxes (Chrome 131 and later). |
[page], [topage] | <span class="pageNumber">, <span class="totalPages"> | Inside a header or footer template. |
[title], [webpage], [date] | class="title", "url", "date" | |
--javascript-delay 1000 | waitUntil: "networkidle0", page.waitForSelector() | wkhtmltopdf's default delay is 200 ms. |
--window-status ready | page.waitForFunction(() => window.status === "ready") | Works in current Chrome (tested with Chrome 158). |
--zoom 1.25 | scale: 1.25 | Puppeteer accepts 0.1 to 2. |
--outline (default) | outline: true | Experimental in Puppeteer, and off by default. |
--cookie name value | browser.setCookie({ name, value, domain }) | page.setCookie() is deprecated in Puppeteer 26. |
--custom-header name value | page.setExtraHTTPHeaders({ name: value }) | |
--username, --password | page.authenticate({ username, password }) | HTTP authentication. |
What replaces wkhtmltopdf wrappers?
Most projects call wkhtmltopdf through a library. Each of these runs wkhtmltopdf underneath, so the fix is to change the library:
| Language | wkhtmltopdf wrapper | Replacement |
|---|---|---|
| Python | pdfkit | Playwright for Python (page.pdf), or WeasyPrint for HTML you control |
| PHP and Laravel | KnpLabs Snappy, barryvdh/laravel-snappy | spatie/browsershot (Puppeteer); spatie/laravel-pdf, which can use Browsershot, Gotenberg, WeasyPrint or DOMPDF; gotenberg/gotenberg-php |
| Ruby on Rails | wicked_pdf | Grover (Puppeteer) |
| .NET | DinkToPdf (no commits since 2020) | PuppeteerSharp, or Playwright for .NET |
| Any language | Gotenberg over HTTP |
In Python, the pdfkit call pdfkit.from_url("https://example.com", "page.pdf") becomes this (pip install playwright, then playwright install chromium):
from playwright.sync_api import sync_playwrightwith sync_playwright() as p:browser = p.chromium.launch()page = browser.new_page()page.emulate_media(media="screen") # wkhtmltopdf's defaultpage.goto("https://example.com", wait_until="networkidle")page.pdf(path="page.pdf", format="A4", print_background=True)browser.close()
For templates you render yourself, WeasyPrint needs no browser at all (pip install weasyprint with Pango 1.44 or later, or brew install weasyprint on macOS; see its installation steps). From the command line it is weasyprint invoice.html invoice.pdf; from Python:
from weasyprint import HTMLHTML("invoice.html").write_pdf("invoice.pdf")
How do I run a PDF service like wkhtmltopdf, but with Chrome?
Gotenberg packages Chromium and LibreOffice behind an HTTP API in one Docker container, so any language can call it. Start it bound to localhost:
docker run --rm -p "127.0.0.1:3000:3000" gotenberg/gotenberg:9
# A URLcurl --request POST http://localhost:3000/forms/chromium/convert/url \--form url=https://example.com \-o example.pdf# Your own HTML: the entry file must be named index.htmlcurl --request POST http://localhost:3000/forms/chromium/convert/html \--form files=@index.html \--form files=@style.css \-o invoice.pdf
Gotenberg prints on Letter paper by default, while wkhtmltopdf uses A4: add --form paperWidth=210mm --form paperHeight=297mm to either call for A4. Without a file named index.html the HTML route answers 400. Tested with Gotenberg 9.12.0.
Gotenberg's documentation says to keep it behind your firewall, because it loads the URLs and runs the documents you send it. Pin an exact version (for example gotenberg/gotenberg:9.12.0) in production.
What replaces wkhtmltoimage?
wkhtmltopdf ships a second tool, wkhtmltoimage, for screenshots. The same engines replace it: headless Chrome with --screenshot=page.png --window-size=1440,900, Puppeteer or Playwright with page.screenshot({ fullPage: true }), or a screenshot API. See Playwright screenshots and website screenshots with an API.
Can URLBooth replace wkhtmltopdf?
For public web pages, yes. URLBooth renders PDFs with screen CSS and backgrounds on, the same defaults as wkhtmltopdf, so pages keep the look they had. Choose letter, a4, legal or a3, or leave paper out to get the whole page as one continuous sheet. Lazy-loaded images are scrolled into view and cookie banners are removed on a best-effort basis.
curl --fail-with-body "https://urlbooth.com/v1/screenshots" \-H "Authorization: Bearer $URLBOOTH_API_KEY" \-H "Content-Type: application/json" \-d '{"url":"https://example.com","format":"pdf","paper":"a4"}' \-o page.pdf
It is not a drop-in replacement for every use: it takes a public URL, not an HTML string or a file, so templates must be served at a URL first; pages behind a login cannot be captured; and there are no header or footer templates or page numbers. For those, use one of the tools above. Details are in the HTML to PDF API guide and the options reference, and the free website to PDF tool converts a single page without an account.
Is it safe to convert untrusted HTML?
Not with wkhtmltopdf, and not casually with the alternatives either. Any browser-based converter loads every URL the HTML points to, which lets crafted HTML reach internal services or local files. Browsershot states that it “is not a sandbox for untrusted content”, and Gotenberg asks you to keep it behind your firewall. If users supply the HTML, render it in an isolated container that cannot reach your internal network.
Sources
Checked on 2026-12-04.
- wkhtmltopdf: project status (maintainer's essay)
- wkhtmltopdf on GitHub (archived)
- wkhtmltopdf usage and options
- Chrome Headless command-line reference
- Chrome: add content to the margins of printed pages (Chrome 131)
- Puppeteer PDFOptions
- Playwright page.pdf()
- Gotenberg: install and first PDF
- WeasyPrint documentation
- Prince licence FAQ
- Prince licences and prices
- JavaScript in Prince
Related guides
- Puppeteer PDF: generate a PDF from a web page
page.pdf() code for Node.js, paper sizes, backgrounds, common problems and fixes, and the same PDF from one API request.
- Playwright PDF: save a web page as PDF
page.pdf() code, why the PDF looks different from the screen, backgrounds and page breaks, and the one-request alternative.
- HTML to PDF API: convert a URL to PDF
curl and Node.js examples, paper sizes or one continuous page, errors and limits. It takes a public URL, not raw HTML.
- Free tool: website to PDF
Convert any public URL to a PDF with selectable text and working links.