Execute wkhtmltopdf from PHP

余生颓废 提交于 2019-12-04 01:52:12

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

Andrei Sandulescu

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

Hope these are usefull to others

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