Execute wkhtmltopdf from PHP

时光怂恿深爱的人放手 提交于 2019-12-09 15:08:36

问题


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.


回答1:


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




回答2:


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



回答3:


Here a PHP wrapper around wkhtmltopdf http://mikehaertl.github.com/phpwkhtmltopdf/ Very simple




回答4:


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



回答5:


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!




回答6:


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/wkhtmlto­pdf --version"); echo($out); 
  $out = passthru('/usr/local/bin/wkhtml2pdf

Hope these are usefull to others



来源:https://stackoverflow.com/questions/6153480/execute-wkhtmltopdf-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!