Migration guides · PHP
Replace wkhtmltopdf with pdfkiln in phpwkhtmltopdf
mikehaertl/phpwkhtmltopdf builds wkhtmltopdf command lines from PHP arrays. It finds the program in the PATH, or takes its path in the binary option.
1. Install pdfkiln
On a Linux server, the Debian package is the better way: it brings Chromium’s system libraries, and its security fixes with apt upgrade.
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
On a development machine, or wherever the Debian package does not fit, the Composer package puts wkhtmltopdf and wkhtmltoimage in vendor/bin and downloads the program of the platform on first use, its SHA-256 checked:
composer require pdfkiln/pdfkiln
2. Point phpwkhtmltopdf at it
use mikehaertl\wkhtmlto\Pdf;
use mikehaertl\wkhtmlto\Image;
$pdf = new Pdf(['binary' => '/usr/bin/wkhtmltopdf']);
$image = new Image(['binary' => '/usr/bin/wkhtmltoimage']);
// With the Composer package
$pdf = new Pdf(['binary' => Pdfkiln\binary()]);
With the Debian package, /usr/bin/wkhtmltopdf is in the PATH: the option can go.
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 phpwkhtmltopdf expects, and what pdfkiln does
- phpwkhtmltopdf passes your options as you write them: every option of wkhtmltopdf 0.12.6 is accepted, 122 of 122, and one it never knew is refused, as wkhtmltopdf refused it.
Tested
phpwkhtmltopdf 2.5.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.