如何在 Symfony2 应用程序中访问 /wkhtmltox/bin/wkhtmltopdf
How to access /wkhtmltox/bin/wkhtmltopdf whithin an Symfony2 Application
我使用 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'
通过将它安装在 vendor 文件夹中,您将不再依赖于您 运行 您的应用程序的机器。
我通过谷歌搜索找到了这个post,所以我post正在考虑我的解决方案以防它对某人有帮助。
在我的例子中,KNP Snappy 的命令 运行 是 vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
,我从中得到了相同的 "no such file or directory" 错误。
我很困惑,因为我可以看到这个文件,而且它是可执行的:
$ 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.
我使用 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'
通过将它安装在 vendor 文件夹中,您将不再依赖于您 运行 您的应用程序的机器。
我通过谷歌搜索找到了这个post,所以我post正在考虑我的解决方案以防它对某人有帮助。
在我的例子中,KNP Snappy 的命令 运行 是 vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386
,我从中得到了相同的 "no such file or directory" 错误。
我很困惑,因为我可以看到这个文件,而且它是可执行的:
$ 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.