Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute wkhtmltopdf from PHP

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.

like image 200
Ginger Opariti Avatar asked May 27 '11 14:05

Ginger Opariti


People also ask

How do I run Wkhtmltopdf?

Open a command prompt window. The syntax for using the tool is fairly simple, enter the name wkhtmltopdf, followed by the URL of the web page, and the name of the PDF that you want to create, like so.


2 Answers

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")
like image 83
Andrew Starlike Avatar answered Oct 09 '22 14:10

Andrew Starlike


wkhtmltopdf has bindings, one of them is for PHP. You could give those a shot.

like image 38
Jimmy Sawczuk Avatar answered Oct 09 '22 16:10

Jimmy Sawczuk