如何在php中填写PDF表单 [英] How to fill PDF form in php

查看:215
本文介绍了如何在php中填写PDF表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多PDF格式的表单,我需要使用我已有的数据在php中填充它们。

这里只是一个示例PDF表单,我想用php填写这个表单。我已经在数据库中存储的数据。



我正在使用PHP Zend Framework。



全部我想要的是,当我从我的网站上下载这些表单时,它会预先填写pdf表单中的所有字段和我已有的信息。



请帮助我。

解决方案

调用 pdftk 是一个很好的方法来实现这一点。我假设你知道如何执行一个外部程序,并将其保留。



首先,从您的PDF创建一个 FDF 文件。

  pdftk form.pdf generate_fdf输出数据.fdf 

您现在可以将其用作模板。您提供的样本如下所示:

 %FDF-1.2 
%< E2>< E3> < CF>< D3>
1 0 obj
<<
/ FDF
<<
/ Fields [
<<
/ V()
/ T(日期)
>>
<<
/ V /
/ T(CheckBox2)
>>
<<
/ V /
/ T(CheckBox3)
>>
<<
/ V /
/ T(CheckBox4)
>>
<<
/ V /
/ T(CheckBox5)
>>
<<
/ V()
/ T(Your_Last_Name)
>>
<<
/ V()
/ T(Your_First_Name)
>>
<<
/ V /
/ T(CheckBox1)
>>]
>>
>>
endobj
预告片

<<
/ Root 1 0 R
>>
%% EOF

这些字段是以 / V()。输入你想要的值到这些字段中。例如:

 %FDF-1.2 
%< E2>< E3>< CF>< D3>
1 0 obj
<<
/ FDF
<<
/ Fields [
<<
/ V(2012年2月4日)
/ T(日期)
...

最后,将FDF与PDF合并。执行命令:

  pdftk form.pdf fill_form data.fdf输出form_with_data.pdf 

如果您不需要保留FDF和生成的PDF文件,只需通过stdin和stdout而不是使用临时文件来管理数据。

I have many PDF forms, I would need to fill them each in php with the data I already have.

Here is just a sample PDF form , I want to fill this form using php. The data I already have in DB. I just want to fill this form and save it.

I am working in PHP Zend Framework.

All I want is when I would download those forms from my site, it would pre-fill all the fields in the pdf form with the information I already have.

Please help me.

解决方案

Calling pdftk is a nice way to accomplish this. I'll assume that you know how to execute an external program and leave that out.

First, create an FDF file from your PDF.

pdftk form.pdf generate_fdf output data.fdf

You can now use that as template. The sample that you provided looks like this:

%FDF-1.2
%<E2><E3><CF><D3>
1 0 obj 
<<
/FDF 
<<
/Fields [
<<
/V ()
/T (Date)
>> 
<<
/V /
/T (CheckBox2)
>> 
<<
/V /
/T (CheckBox3)
>> 
<<
/V /
/T (CheckBox4)
>> 
<<
/V /
/T (CheckBox5)
>> 
<<
/V ()
/T (Your_Last_Name)
>> 
<<
/V ()
/T (Your_First_Name)
>> 
<<
/V /
/T (CheckBox1)
>>]
>>
>>
endobj 
trailer

<<
/Root 1 0 R
>>
%%EOF

The fields are lines that start with /V (). Enter your desired values into those fields. For example:

%FDF-1.2
%<E2><E3><CF><D3>
1 0 obj 
<<
/FDF 
<<
/Fields [
<<
/V (February 4, 2012)
/T (Date)
...

Finally, merge the FDF with the PDF. Execute the command:

pdftk form.pdf fill_form data.fdf output form_with_data.pdf

If you don't need to keep the FDF and generated PDF files, you can simply pipe the data via stdin and stdout instead of using temp files.

这篇关于如何在php中填写PDF表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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