使用 PHP 将 FDF 数据合并到 PDF 文件中
是否可以单独使用 PHP 将 FDF 数据与 PDF 文件合并?或者除了使用第三方命令行工具来实现这一点之外别无选择?
如果是这种情况,有人可以给我指出一个方向吗?
我目前正在将 FDF 文件输出到浏览器,希望它将用户重定向到填写的 PDF,但对于某些人来说情况并非如此。 FDF 内容正在输出到屏幕,即使我使用 header('Content-type: application/vnd.fdf');
Is it possible to merge FDF data with a PDF file using PHP alone? Or is there no option but to use a 3rd party command line tool to achieve this?
If that is the case can someone point me in the direction of one?
I am currently outputting the FDF file to the browser in the hope that it will redirect the user to the filled in PDF but for some people that is not the case. The FDF contents is being output to the screen, even though I am using header('Content-type: application/vnd.fdf');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了将来的参考,如果没有第 3 方应用程序,似乎没有可靠的方法来做到这一点。 Pdftk (http://www.accesspdf.com/pdftk/) 最终成为我的解决方案。
我首先像以前一样生成 FDF 文件,然后使用以下 PHP 代码将其合并到我的 PDF 文件中,
这比我想象的要容易得多。这立即消除了对标头和文件扩展名进行修改的需要,以确保所有浏览器正确处理 FDF,因为它只是让浏览器下载 PDF 文件。
如果您希望 PDF 输出文件不再可编辑,请使用
道歉(如果这是基本内容),只是想我将其全部放在一个地方,这样人们就不会经历我所忍受的头痛。
注意:如果您的 PATH 变量未设置,您将需要使用 pdftk 的完整路径,即
For future reference, it looks like there isn't a reliable way of doing it without a 3rd party app. Pdftk (http://www.accesspdf.com/pdftk/) ended up being my solution.
I first generated the FDF file as before, and then merged it into my PDF file using the following PHP code
It was much easier than I thought it would be. This instantly eliminates the need to hack around with headers and file extensions to ensure all browsers handle an FDF properly, as it simply makes the browser download the PDF file.
If you want the PDF output file to no longer be editable, use
Apologies if this is basic stuff, just thought I'd put it all in one place so that people don't go through the headache that I endured.
N.B. If your PATH variable is not set, you will need to use the full path to pdftk i.e.
今天还有另一种方法,不使用 passthru 也不使用 pdftk,而只是使用 2004 年编写的脚本,但仍然运行良好: forge_fdf< /a>
它可以帮助您构建一个可以直接合并到 pdf 中的 fdf,这意味着您
将其保存在 php 文件中,比方说generatePdf.php
建立一个指向 Pathtoyourpdf/nameofpdffile.pdf#FDF=generatePdf.php 的链接将在浏览器中打开您的 PDF 文件(或者有一种方法可以将其保存到磁盘,我想我记得)并且字段电子邮件将填充来自 MYSQL 的数据:
mb_strtolower($row_delivreur['firstname'])。 .'.mb_strtolower($row_delivreur['lastname']).'@gmail.com'
它适用于复选框、单选按钮...它在 Firefox 中打开得很好,必须使用其他浏览器进行测试。
有关 PDF 黑客
There is another way to day that not using passthru nor pdftk but just a script made in 2004 but still working well : forge_fdf
it helps you to build a fdf that you can incoporate straithly in your pdf, it means that you
Save this in a php file, let's say generatePdf.php
Making a link to Pathtoyourpdf/nameofpdffile.pdf#FDF=generatePdf.php will open your PDF file in browser (alternatively there is a way to save it to disk i think i remember) and the field email will be filled with data from MYSQL :
mb_strtolower($row_delivreur['firstname']).'.'.mb_strtolower($row_delivreur['lastname']).'@gmail.com'
It works with checkboxes, radio button,... It opens well in firefox, it has to be tested with other browsers.
More infos on PDF HACKS
到目前为止,我发现在centos上安装pdftk的最简单方法:
安装rpmforge repo - http ://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b
然后
yum install pdftk
就这样了!
by far the easiest way I have found to install pdftk on centos:
Install rpmforge repo - http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b
then
yum install pdftk
and thats it!
http://www.setasign.de/products/ pdf-php-solutions/fpdi/demos/concatenate-fake/
这有效,类下载也从网站链接到,
它不需要 passthru/exec 命令,也不需要额外的扩展。
编辑说,这不适用于较新的 pdf 版本 1.5+,恢复为 PDFTK,需要繁琐的操作,但可以使用“exec”命令处理所有 pdf。
http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/concatenate-fake/
This works , the classes download are linked to from the web site too,
It requires no passthru/exec command and no additional extensions.
Edited to say, this doesn't work with newer pdf versions 1.5+, reverted to PDFTK, fiddly but works with all pdfs using the 'exec' command.