Executing wkhtmltopdf from PHP fails

假如想象 提交于 2019-12-19 06:57:31

问题


There have been a few topics similar to mine, but they did not help me. Maybe something new will come up.

Problem: I can't execute wkhtmltopdf form PHP. My basic code is: exec('wkhtmltopdf http://somesite.com /home/user/file.pdf');

Now a few things I already checked:

  • the same command works when executed from console
  • safe_mode is disabled - I can execute commands in PHP, for example exec('ls'); works fine
  • path to wkhtmltopdf can be found and I can run the program itself, for example exec('wkhtmltopdf -V'); works fine and outputs versioning info
  • the output path is writable, it has 777 permissions and exec('wkhtmltopdf -V > /home/user/file.pdf'); works fine, creates the file and puts versioning info inside
  • executing from PHP has internet access, for exemple exec('wget -O /home/user/file.pdf http://somesite.com') works fine, retrieves the site source and puts it into the file
  • replacing exec with passthru, shell_exec etc. makes no difference

Concluding: I can execute wkhtmltopdf, I can access internet, I can write the specific file, but a correct conversion command fails and returns status 1.

I use the latest Ubuntu, PHP Version is 5.3.10-1ubuntu3, wkhtmltopdf version is 0.9.9. I tried it also on some other machine with the same retults.

Any (just ANY) ideas will be greatly appreciated!


回答1:


Add 2>&1 to the end of your command to understand the exact error.

exec('wkhtmltopdf http://somesite.com /home/user/file.pdf 2>&1');

This way it will tell you the error when running this under Apache. Once you know what's wrong, it is easier to address. I had a similar problem before with ImageMagick



来源:https://stackoverflow.com/questions/10631605/executing-wkhtmltopdf-from-php-fails

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