Migration guides · PHP, Laravel

Replace wkhtmltopdf with pdfkiln in laravel-snappy

barryvdh/laravel-snappy brings knp-snappy to Laravel (SnappyPdf::loadView(), SnappyImage). Two lines of .env move it to pdfkiln.

1. Install pdfkiln

On a Linux server, take the Debian package: it brings Chromium’s system libraries, and its 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; the program is fetched on first use, 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 1.0.4, Chromium 156.0.8078.80

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: --lowquality is accepted without a word, and nothing goes to the error output when all goes well.
  • Point it at wkhtmltopdf, never at pdfkiln, which 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.