Everyone loves PDF: CEOs, CFOs, marketing people, even the postman and the milkman, everyone except developers that need to convert HTML pages to PDF.
Fortunately, there are quite a few libraries that help the poor PHP developer in his task, some are native implementations, others are a wrapper for a CLI application.
One of these is Snappy
, a popular (22M+ downloads) library that wraps wkhtmltopdf
.
wkhtmltopdf
is good, until you encounter that HTML code that renders awfully or you hit one of wkhtmltopdf’s missing features, that’s what happened to me.
I’ve started looking for an alternative solution and found WeasyPrint : after a couple of changes in CSS style my PDF came out as my customer wanted.
So I started packaging my solution, building on the shoulder of a giant, adapting Snappy code, that served me well, to WeasyPrint CLI API.
I released the resulting library on my company GitHub: pontedilana/php-weasyprint is MIT licensed and one-to-one swappable with Snappy.
I also adapted KnpSnappyBundle to work with php-weasyprint, as we use Symfony as our main framework: WeasyPrintBundle is tested with Symfony 4.4 and 5.3.
I hope that these two packages can be useful for some of you.