Migration guides · PHP, Laravel
Replace wkhtmltopdf with pdfkiln in laravel-snappy
barryvdh/laravel-snappy brings knp-snappy to Laravel: SnappyPdf::loadView() and SnappyImage run wkhtmltopdf and wkhtmltoimage underneath. Two lines of .env move them to pdfkiln.
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 laravel-snappy at it
# .env, read by config/snappy.php (pdf.binary, image.binary)
WKHTML_PDF_BINARY=/usr/bin/wkhtmltopdf
WKHTML_IMG_BINARY=/usr/bin/wkhtmltoimage
With the Composer package, set the binaries in config/snappy.php instead:
'pdf' => ['binary' => Pdfkiln\binary(), /* ... */],
'image' => ['binary' => Pdfkiln\binary('wkhtmltoimage'), /* ... */],
If the configuration is cached, clear it: php artisan config:clear.
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 laravel-snappy expects, and what pdfkiln does
- laravel-snappy runs knp-snappy:
--lowqualityis accepted without a word, and nothing is written on the error output when all goes well. - Point it at
wkhtmltopdf, never atpdfkiln: called by that name, the program switches to its own interface.
Tested
laravel-snappy calls knp-snappy, whose own test suite passes with pdfkiln (knp-snappy 1.7.3, 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.