Execute wkhtmltopdf from PHP

Ginger Opariti picture Ginger Opariti · May 27, 2011 · Viewed 23k times · Source

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.

Answer

Andrei Sandulescu picture Andrei Sandulescu · Oct 7, 2012

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")