使用PHP将FDF数据合并为PDF文件 [英] Merge FDF data into a PDF file using PHP

查看:157
本文介绍了使用PHP将FDF数据合并为PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅使用PHP将FDF数据与PDF文件合并?还是别无选择,只能使用第三方的命令行工具来实现这一目标?

如果是这样的话,有人可以将我指向一个方向吗?

我目前正在将FDF文件输出到浏览器,希望它将用户重定向到已填写的PDF,但对于某些人来说并非如此.即使我正在使用header('Content-type:application/vnd.fdf');

解决方案

供以后参考,如果没有第三方应用程序,似乎没有可靠的方法. Pdftk( http://www.accesspdf.com/pdftk/)最终成为我的解决方案. /p>

我首先像以前一样生成FDF文件,然后使用以下PHP代码将其合并到我的PDF文件中

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Download.pdf"');
passthru("pdftk file.pdf fill_form data.fdf output - ");
exit;

这比我想象的要容易得多.这样一来,您就无需再纠缠头文件和文件扩展名,以确保所有浏览器都能正确处理FDF,因为这只会使浏览器下载PDF文件.

如果您希望PDF输出文件不再可编辑,请使用

    passthru("pdftk file.pdf fill_form data.fdf output - flatten");

很抱歉,如果这是基本内容,只是想我将所有内容都放在一个地方,这样人们就不会再忍受我所忍受的头痛了.

如果未设置PATH变量,则需要使用pdftk的完整路径,即

    passthru("/usr/local/bin/pdftk file.pdf fill_form data.fdf output - flatten");

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');

解决方案

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

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Download.pdf"');
passthru("pdftk file.pdf fill_form data.fdf output - ");
exit;

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

    passthru("pdftk file.pdf fill_form data.fdf output - flatten");

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("/usr/local/bin/pdftk file.pdf fill_form data.fdf output - flatten");

这篇关于使用PHP将FDF数据合并为PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆