从数据库填充PDF字段 [英] Populating PDF fields from a database

查看:177
本文介绍了从数据库填充PDF字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PDF文件(不是由我创建的-我无法控制设计等),它使用户可以在Adobe Reader中填写某些表格字段并保存结果.我想使用以下步骤来自动化填充字段的过程:

I have a PDF file (not created by me - I have no control over the design etc.) which allows users to fill in some form fields in Adobe Reader and save the result. I want to automate the process of populating the fields, using the following steps:

  1. 从数据库中获取数据.
  2. 打开PDF模板.
  3. 用数据填充表单字段.
  4. 将修改后的文件保存到磁盘上的单独位置.
  5. 锁定修改的文件,以便不再可以编辑表单字段.
  6. 发送文件给用户.

我很高兴使用PHP,Perl,Python或Java来执行步骤2-5(按优先级从高到低的顺序),但是我使用的任何东西都必须在Linux下工作(即,它不能依赖于以下库)例如仅在Windows上可用.

I'm happy to use PHP, Perl, Python or Java to do steps 2-5 (in descending order of preference), but whatever I use has to work under Linux (i.e. it mustn't rely on libraries which are only available on Windows for example).

最终结果应该是普通用户可以打开和打印但不能修改的PDF(我相信高级用户可以找到一种方法,但是我接受我不能保证完全安全的修改权限) ).我不想更改PDF的结构,只需填充表单字段即可.

The end result should be a PDF which the average user can open and print, but not modify (I'm sure advanced users could find a way to do so, but I accept that I can't guarantee complete security against modification). I don't want to change the structure of the PDF, merely populate the form fields.

是否有用于执行此操作的标准软件?我已经提到过FDF Toolkit,但是我不确定这是否是我想要的,是否可以让我以后锁定文件,以及我想做什么与EULA相符.

Is there a standard piece of software for doing this? I've seen mentions of FDF Toolkit, but I'm not entirely sure if that's what I want and whether it will allow me to lock the file afterwards, and whether what I want to do fits in with the EULA.

最终的答案是使用iText(如Mark Storer所建议),但是将其实现为Web服务,该服务允许您传递一组表单字段名称和值以及PDF文件模板".根据AGPL,该Web服务将是开源的(在我写完后就可以在GitHub上使用),但是与它连接的任何内容都不必是

Final answer is to use iText (as suggested by Mark Storer) but to implement it as a web service which allows you to pass in an array of form field names and values and the PDF file 'template'. The web service will be open source (and available on GitHub once I've written it), as per the AGPL, but anything connecting to it won't have to be.

推荐答案

填充

任何数量的不同库都可以填写字段值.我偏爱iText(java)或iTextSharp(c#).几年前,我用Java编写了一个.这并不难).有很多.搜索,您会找到'em.

Filling

Any number of different libraries can fill in field values. I'm partial to iText (java) or iTextSharp (c#). I wrote one in Java a number of years ago. It's not that hard). There are lots. Search SO, you'll find 'em.

锁定字段"有几个不同的级别.

There are a couple different levels of "lock the fields".

  • 每个字段都有一个只读"标志.就其他能够设置字段值的库而言,这几乎是礼貌的.实际上,通常认为它是指"UI无法进行更改".表单脚本可以,无论如何.
  • 展平:将字段直接绘制到页面中,并删除所有交互.

每个人都有优点和缺点.

Each one has pros and cons.

标志:都不是太安全.表单数据仍然易于访问.滚动字段仍在滚动.
平移:几乎完全相反.修改起来比较困难(尽管远非不可能).表单数据只能通过文本提取来提取(这很困难,但变得越来越普遍).清单和包含的内容多于可见内容的文本字段将不再滚动.

Flag: None too secure. Form data still easily accessible. Scrolling fields still scroll.
Flattening: Pretty much the exact opposite. It's harder to modify (though far from impossile). The form data can only be extracted via text extraction (which is hard, but becoming increasingly common). List & text fields that contain more stuff than is visible will no longer scroll.

使表格扁平化的能力相对罕见.同样,iText可以做到这一点(iTextSharp可以做到),但是我不知道其他任何第三方库都可以...我确定它们存在,只是无法将它们命名.

The ability to flatten forms is relatively rare. Again, iText can do it (as can iTextSharp), but I'm not aware of any other third party libraries that can... I'm sure they exist, I just can't name them off the top of my head.

这篇关于从数据库填充PDF字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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