我使用KnpSnappyBundle在我的Symfony2应用程序中生成PDF。 它在我的本地 wamp 上工作正常,配置如下:
binary: ""C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe""
我尝试使用该应用程序,但根目录中有一个带有 wkhtmltox 的文件夹,其配置为:
binary: %kernel.root_dir%/../wkhtmltox/bin/wkhtmltopdf
它不起作用。它收到以下消息:
The exit status code '127' says something went wrong:
stderr: "sh: wkhtmltox/bin/wkhtmltopdf: No such file or directory
"
stdout: ""
command: wkhtmltox/bin/wkhtmltopdf --lowquality
'/tmp/knp_snappy595a4fa89a6676.24945632.html'
'/tmp/knp_snappy595a4fa89a6a59.72414975.pdf'.
我正在使用 OVH 的虚拟主机服务器。
您可以尝试从 https://github.com/h4cc/wkhtmltopdf-amd64 安装wkhtmltopdf
需要 i386 的软件包,包括:
composer require h4cc/wkhtmltopdf-i386 "0.12.3"
对于 amd64,具有:
composer require h4cc/wkhtmltopdf-amd64 "0.12.3"
然后,二进制文件将位于:
vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
或
vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64
对于后者,services.yml 将如下所示:
knp_snappy:
pdf:
enabled: true
binary: '%kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'
options: []
temporary_folder: '%kernel.cache_dir%/snappy'
通过将其安装在供应商文件夹中,您将不再依赖于运行应用程序的计算机。
我通过谷歌搜索找到了这篇文章,所以我发布了我的解决方案,以防它对某人有所帮助。
在我的情况下,KNP Snappy运行的命令vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
,我从中得到了相同的"没有这样的文件或目录"错误。
我很困惑,因为我可以看到这个文件,它是可执行的:
$ ls -al vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
-rwxr-xr-x 1 1000 1000 41424004 Nov 7 09:07 vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
但是当我尝试运行它时...
$ vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
-bash: vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386: No such file or directory
我很困惑,因为错误似乎是可执行文件不存在,而且它显然确实存在。
事实上,问题是我尝试使用32位版本的可执行文件,而我的机器是64位的:
$uname -a
Linux mybox 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
(见amd64
部分(
所以我不得不在 config.yml 中更新这一位:
knp_snappy:
pdf:
binary: # this was the path to the 32-bit executable; I had to update it to use the 64-bit version.