简体   繁体   English

用php填充可编辑的PDF表单字段

[英]Populate editable PDF form fields with php

I've got an existing PDF form that my office has created that has form fields for the user to fill out (electronically) and print. 我的办公室已经创建了一个现有的PDF表单,其中包含供用户(电子)填写和打印的表单字段。 Before passing it to the user I would like to open the existing PDF and populate as much (if not all) of that data using php. 在将其传递给用户之前,我想打开现有的PDF并使用php填充尽可能多(如果不是全部)的数据。 I've looked into extensions like TCPDF and FPDI, but I'm unable to confirm that what I want to do is even possible by looking at the examples and documentation. 我已经研究了TCPDF和FPDI之类的扩展,但是我无法通过查看示例和文档来确认我想做什么。 Have any of you done this before? 你们有做过吗?

I did see TCPDF::setFormDefaultProp , which looked promising... 我确实看到了TCPDF :: setFormDefaultProp ,看起来很有希望...

Pdftk has a fill_form command. Pdftk具有fill_form命令。 Since it doesn't have PHP bindings you'll have to install it on your server and invoke it with exec() et al but it's pretty easy. 由于它没有PHP绑定,因此您必须将其安装在服务器上并使用exec()等调用它,但这非常简单。 To use it you'll have to generate an FDF file, which Pdftk will do given the generate_fdf command, then plug the desired data into it. 要使用它,您必须生成一个FDF文件,Pdftk会在指定generate_fdf命令的情况下执行该操作,然后将所需的数据插入其中。 You can find some information on FDF files here and some example PHP code here and here . 你可以找到关于FDF文件的一些信息, 这里还有一些例如PHP代码在这里这里 In truth I think you could just put the generated FDF file in your PDF script and, given the right escaping, fill the values like you would in any string, then pipe it back into pdftk fill_form . 实际上,我认为您可以将生成的FDF文件放入PDF脚本中,并在正确转义的情况下,像在任何字符串中一样填充值,然后将其通过管道pdftk fill_formpdftk fill_form

您可以使用SetPDF http://www.setasign.com/等商业产品

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM