从 PHP 执行 wkhtmltopdf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6153480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Execute wkhtmltopdf from PHP
提问by Ginger Opariti
I have this working fine from Linux command line:
我在 Linux 命令行中运行良好:
wkhtmltopdf entry.html output.pdf
wkhtmltopdf entry.html output.pdf
But the following doesn't work from PHP code:
但是以下内容不适用于 PHP 代码:
exec ('wkhtmltopdf entry.html output.pdf');
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.
有趣的是,我用谷歌搜索了很多未经检查的解决方案,但没有解释为什么这是一个问题。谢谢如果你有好的。
采纳答案by Jimmy Sawczuk
回答by Andrei Sandulescu
had the same problem and i don't think anyone else should waste > 3 hours:
有同样的问题,我认为其他人不应该浪费 > 3 小时:
the solution is here: wkhtmltopdf error in apache log
解决方案在这里:apache 日志中的 wkhtmltopdf 错误
you just have to install xvfp "to emulate a x-environment"
你只需要安装 xvfp“来模拟一个 x 环境”
exec("xvfb-run -a wkhtmltopdf test.html output.pdf")
回答by nxplace
Here a PHP wrapper around wkhtmltopdf http://mikehaertl.github.com/phpwkhtmltopdf/Very simple
这里是 wkhtmltopdf http://mikehaertl.github.com/phpwkhtmltopdf/的 PHP 包装器, 非常简单
回答by Phil
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!
刚刚遇到这个问题 - 在我的情况下的简单解决方案:我没有意识到 PHP 处于安全模式。关闭安全模式,它工作正常!
回答by joar
Perhaps wkhtmltopdf
is not in the PATH variable for www-data.
也许wkhtmltopdf
不在 www-data 的 PATH 变量中。
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/...
*nix 机器上。然后像这样在你的命令wkhtmltopdf
中用eg替换/usr/bin/wkhtmltopdf
。
/usr/bin/wkhtmltopdf entry.html output.pdf
回答by jdkos
I was struggling with the same problem.
我正在努力解决同样的问题。
My solution on a Windows 2008 R2
server with PHP 5.4
:
我在Windows 2008 R2
服务器上的解决方案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.
就是这样(在搜索网络超过 5 小时后,包括这个)一个名为 output.txt 的新文件,将其重命名为 output.pdf 并赋予用户“每个人”的权限。
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
希望这些对其他人有用