Migration guides · Ruby on Rails
Replace wkhtmltopdf with pdfkiln in wicked_pdf
wicked_pdf renders Rails views to PDF with wkhtmltopdf, which the wkhtmltopdf-binary gem usually installs. Remove the gem, install pdfkiln, and point wicked_pdf at it.
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 wicked_pdf at it
# Gemfile: remove the gem that bundled wkhtmltopdf
# gem 'wkhtmltopdf-binary'
# config/initializers/wicked_pdf.rb
WickedPdf.config = { exe_path: '/usr/bin/wkhtmltopdf' }
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 wicked_pdf expects, and what pdfkiln does
- wicked_pdf reads
wkhtmltopdf --versionto choose its syntax, with the expressionwkhtmltopdf\s*(\d*\.\d*\.\d*\w*): pdfkiln starts its answer withwkhtmltopdf 0.12.6, so wicked_pdf keeps the current syntax. - Headers and footers rendered from views are
--header-htmland--footer-htmlpages: their JavaScript, and the variables wkhtmltopdf puts in their query string (page,topage,section…), work unchanged.
Tested
wicked_pdf 2.7.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.