从 PHP 脚本执行 PDFTk 失败,错误代码为 11
我正在尝试从 PHP 脚本填写 PDF。我正在关注 Sid Steward 的文章,网址为:网址。
我已经在 CentOS Linux 发行版上配置了 PDFTk 软件包,并且我能够从命令提示符执行 pdftk,它将 FDF 表单与 PDF 合并并成功生成扁平化的(已填充)PDF。我正在使用以下命令来使用 shell 测试 Pdftk。
pdftk /tmp/form.pdf fill_form /tmp/fdfbm0pe7 output /tmp/filledform.pdf flatten
但是当尝试通过 PHP 执行类似的命令时,我收到错误。 passthru 命令失败,错误代码为 11。以下是我用来执行命令的 php 代码:
$command = 'pdftk form.pdf fill_form '. $fdf_fn. ' output - flatten';
passthru($command, $error);
上面的 $fdf_fn 具有 FDF 文件名。 form.pdf 是可填写的 pdf 表单。 form.pdf 和我给出上述代码行的 PHP 脚本文件都位于同一文件夹中。我已经通过回显 shell_exec('pdftk') 检查了 PDFtk 是否通过 PHP 正确执行,并且它返回了标准帮助详细信息。
为了提供更多详细信息,pdftk 的路径是 /usr/bin/,PHP 脚本和 PDF 表单文件位于 /var/www/html/pdfmerge 下。
有人可以指导我做错了什么吗?通过 PHP 执行命令失败,错误代码为 11?
I am trying to Fill in a PDF from PHP script. I am following the article by Sid Steward at the following URL.
I have configured PDFTk package on CentOS linux distribution and I am able to execute the pdftk from the command prompt and it merges the FDF form with the PDF and successfully generates the flattened(Filled) PDF. I am using following command to test the Pdftk using shell.
pdftk /tmp/form.pdf fill_form /tmp/fdfbm0pe7 output /tmp/filledform.pdf flatten
But When try to execute a similar command through PHP, I am getting the error. The passthru command is failing with error code 11. Following is the php code I am using to execute the command:
$command = 'pdftk form.pdf fill_form '. $fdf_fn. ' output - flatten';
passthru($command, $error);
The $fdf_fn above has the FDF file name. The form.pdf is the fill-able pdf form. Both the form.pdf and the PHP script file from which I have given the above lines of code are in the same folder. I have checked that PDFtk is executing correctly through PHP by echoing shell_exec('pdftk') and it was returning the standard help details.
Just to provide more details, the path to pdftk is /usr/bin/ and PHP script and PDF form files are located under /var/www/html/pdfmerge.
Can some one please guide what I am doing wrong that the command execution through PHP is failing with error code 11?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 CentOS 上运行 PDFTK 时遇到了完全相同的问题,并花了几个小时来寻找问题,所以我希望有人会发现这很有用。我对 PDFTK 的具体用途是用于 Drupal 上的 FillPDF 模块。退出代码 11 问题的解决方案是设置本地策略模块以允许 httpd 运行 PDFTK。如果您像这样 grep /var/log/audit/audit.log 查找 pdftk,
您应该会看到一些错误,其中可能包括“execmem”错误等。以下是我为解决该问题所做的操作...
运行此命令将从日志中提取错误并将其放入文件中供您查看。
如果输出看起来不错(例如有 IS 输出),请运行此命令来创建模块。
创建模块后,您可以通过运行此命令来激活策略。
PDFTK 现在应该从 PHP 运行。如果没有,请通过运行检查 httpd_enable_cgi 是否已打开。
如果未打开,请通过运行将其打开。
有关策略模块的详细信息可以在此处找到:http://wiki.centos.org/HowTos/SELinux#head-faa96b3fdd922004cdb988c1989e56191c257c01
I had the exact same issue with PHP running PDFTK on CentOS and spent a number of hours hunting things down, so I hope someone will find this useful. My specific use for PDFTK is for the FillPDF module on Drupal. The solution to the exit code 11 issue was setting a local policy module to allow httpd to run PDFTK. If you grep /var/log/audit/audit.log for pdftk like this
you should see some errors, probably one for 'execmem', amongst others. Here is what I did to fix the issue...
Running this command will pull the errors out of the log and put them into a file for you to review.
If the output looks good (e.g. there IS output), run this command to create the module.
Once the module is created, you make the policy active by running this command.
PDFTK should run now from PHP. If it does not, check to see if httpd_enable_cgi is on by running
If it is not on, turn it on by running
Details on the policy module can be found here: http://wiki.centos.org/HowTos/SELinux#head-faa96b3fdd922004cdb988c1989e56191c257c01
我遇到了与您遇到的类似问题,事实证明 PHP 无权读取 .pdf、.fdf,并且无权在 /tmp 目录中创建扁平 .pdf 文件。
看看这是否是问题所在,尝试执行此操作
,看看是否可以解决问题。我不建议在 777 离开,但也许可以将其移回 700 左右。
I had a similar issue to what you were having and it turns out that PHP didn't have access to read the .pdf, .fdf and did not have access to create the flattened .pdf file in the /tmp directory.
to see if that is the issue try doing
to see if that fixes the issue. I wouldn't recommend leaving at 777 but maybe moving it back to 700 or so.