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.
wkhtmltopdf has bindings, one of them is for PHP. You could give those a shot.
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")
Here a PHP wrapper around wkhtmltopdf http://mikehaertl.github.com/phpwkhtmltopdf/ Very simple
Perhaps wkhtmltopdf
is not in the PATH variable for www-data.
whereis wkhtmltopdf
will tell you where the binary is located; Binaries usually resides in /usr/bin/...
on *nix machines. Then replace wkhtmltopdf
with e.g. /usr/bin/wkhtmltopdf
in your command like this.
/usr/bin/wkhtmltopdf entry.html output.pdf
Just had this problem - simple solution in my case: I didn't realise that PHP was in Safe Mode. Switched off Safe Mode and it worked fine!
I was struggling with the same problem.
My solution on a Windows 2008 R2
server with PHP 5.4
:
exec('C:\inetpub\wwwroot\mywebsite\subdir\wkhtmltopdf input.html output.pdf');
AND this was it (After > 5 hours searching the net including this) a new file called output.txt, renamed it to output.pdf and give the user 'everybody' rights to it.
These are my tryouts:
exec(C:\inetpub\wwwroot\mywebsite\wkhtmltopdf );
echo(exec(wkhtmltopdf.exe cache.html output.pdf));
exec("xvfb-run -a wkhtmltopdf test.html output.pdf")
$execute = "xvfb-run -a wkhtmltopdf cache.html output.pdf";
$out = shell_exec("/path/to/wkhtmltopdf --version"); echo($out);
$out = passthru('/usr/local/bin/wkhtml2pdf
Hope these are usefull to others
来源:https://stackoverflow.com/questions/6153480/execute-wkhtmltopdf-from-php