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 in its binary option.

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 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 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 phpwkhtmltopdf expects, and what pdfkiln does

  • Your options pass as you write them: all 122 options of wkhtmltopdf 0.12.6 are accepted, 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.