Migration guides · Python
Replace wkhtmltopdf with pdfkiln in pdfkit
pdfkit (python-pdfkit) runs wkhtmltopdf for from_url, from_file and from_string. It finds it in the PATH, or in a configuration you pass.
1. Install pdfkiln
On Debian and Ubuntu (amd64 and arm64), from the signed APT repository, which brings Chromium’s security fixes with apt upgrade. It installs /usr/bin/wkhtmltopdf and replaces the official wkhtmltox package.
curl -fsS https://apt.pdfkiln.org/pdfkiln-archive-keyring.asc | sudo tee /usr/share/keyrings/pdfkiln-archive-keyring.asc > /dev/null
printf 'Types: deb\nURIs: https://apt.pdfkiln.org\nSuites: stable\nComponents: main\nSigned-By: /usr/share/keyrings/pdfkiln-archive-keyring.asc\n' \
| sudo tee /etc/apt/sources.list.d/pdfkiln.sources
sudo apt update && sudo apt install pdfkiln
Elsewhere: the Docker image, the archives and the Windows installer.
2. Point pdfkit at it
import pdfkit
# Nothing to do if wkhtmltopdf is in the PATH: the Debian package puts it in /usr/bin
pdfkit.from_url('https://example.com', 'out.pdf')
# Otherwise, give its path
config = pdfkit.configuration(wkhtmltopdf='/usr/bin/wkhtmltopdf')
pdfkit.from_string(html, 'out.pdf', configuration=config)
On Windows, pdfkiln installs in C:\Program Files\wkhtmltopdf, the path pdfkit’s guides use: pdfkit.configuration(wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe') keeps working.
3. Check
wkhtmltopdf --version
# wkhtmltopdf 0.12.6 (with patched qt), pdfkiln <version>, Chromium <version>
The answer starts as wkhtmltopdf 0.12.6’s does: libraries that read the version keep working.
What pdfkit expects, and what pdfkiln does
- pdfkit sends the page on standard input and reads the PDF on standard output,
-on both sides, with--quiet: pdfkiln handles both. - When the exit code is not 0, pdfkit keeps the PDF if the second-to-last line of the error output is
Done: pdfkiln writes that line, outside--quiet, as wkhtmltopdf did. - Local images and style sheets still need
options={'enable-local-file-access': ''}or--allow: like wkhtmltopdf 0.12.6, pdfkiln lets a page read no other local file by default.
Tested
pdfkit 1.0.0’s own test suite passes with pdfkiln in place of wkhtmltopdf (Ubuntu, CI job libraries).
Something renders differently? Open an issue with the HTML and both PDFs: github.com/Jamalofski/pdfkiln/issues. The known differences are listed in the README.