从 PHP 执行 wkhtmltopdf
我在 Linux 命令行下运行得很好:
wkhtmltopdf 入口.html 输出.pdf
但是以下内容在 PHP 代码中不起作用:
exec('wkhtmltopdfentry.htmloutput.pdf');
有趣的是,我用谷歌搜索了很多未经检查的解决方案,但没有解释为什么这是一个问题。 谢谢,如果你有好的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有同样的问题,我认为其他人不应该浪费> 3小时:
解决方案在这里:wkhtmltopdf error in apache log
你只需安装 xvfp“以模拟 x 环境”
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"
wkhtmltopdf 有 绑定,其中之一是针对 PHP 的。你可以尝试一下。
wkhtmltopdf has bindings, one of them is for PHP. You could give those a shot.
这是 wkhtmltopdf 的 PHP 包装器
http://mikehaertl.github.com/phpwkhtmltopdf/
很简单
Here a PHP wrapper around wkhtmltopdf
http://mikehaertl.github.com/phpwkhtmltopdf/
Very simple
也许
wkhtmltopdf
不在 www-data 的 PATH 变量中。会告诉您二进制文件所在的位置;二进制文件通常驻留在 *nix 机器上的
/usr/bin/...
中。然后在命令中将wkhtmltopdf
替换为 eg/usr/bin/wkhtmltopdf
,如下所示。Perhaps
wkhtmltopdf
is not in the PATH variable for www-data.will tell you where the binary is located; Binaries usually resides in
/usr/bin/...
on *nix machines. Then replacewkhtmltopdf
with e.g./usr/bin/wkhtmltopdf
in your command like this.刚刚遇到这个问题 - 在我的情况下有一个简单的解决方案:我没有意识到 PHP 处于安全模式。关闭安全模式,一切正常!
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 5.4
的Windows 2008 R2
服务器上的解决方案:这就是它(在网络搜索超过 5 小时后,包括这个)一个名为 output.txt 的新文件,将其重命名为 output.pdf 并授予用户“所有人”权限。
这些是我的尝试:
希望这些对其他人有用
I was struggling with the same problem.
My solution on a
Windows 2008 R2
server withPHP 5.4
: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:
Hope these are usefull to others