Php – Execute wkhtmltopdf from PHP

html2pdfPHPwkhtmltopdf

I have this working fine from Linux command line:

wkhtmltopdf entry.html output.pdf

But the following doesn't work from PHP code:

exec ('wkhtmltopdf entry.html output.pdf');

Interesting, I've googled and a lot of non-checked solutions and with no explanation why this is a problem.
Thanks if you have the good ones.

Best Answer

had the same problem and i don't think anyone else should waste > 3 hours:

the solution is here: wkhtmltopdf error in apache log

you just have to install xvfp "to emulate a x-environment"

exec("xvfb-run -a wkhtmltopdf test.html output.pdf")