如何在Java中自动执行PDF表单填充 [英] How to automate PDF form-filling in Java

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

问题描述

我正在为我居住的附近的食品储藏室做一些无偿开发".他们被表格和文书工作所淹没,我想开发一个系统,该系统仅从MySQL服务器读取数据(我在上一个项目中为他们设置),然后将数据馈入其所需的所有表格的PDF版本填写.这将极大地帮助他们,并节省大量时间,并且消除了填写这些表格时出现的许多人为错误.

I am doing some "pro bono" development for a food pantry near where I live. They are inundated with forms and paperwork, and I would like to develop a system that simply reads data from their MySQL server (which I set up for them on a previous project) and feeds data into PDF versions of all the forms they are required to fill out. This will help them out enormously and save them a lot of time, as well as get rid of a lot of human errors that are made when filling out these forms.

对PDF文件的内部情况一无所知,我可以在这里预见两种途径:

Not knowing anything about the internals of PDF files, I can foresee two avenues here:

  • Harder Way :可以扫描纸质文档,将其转换为PDF,然后使用只需填写添加 blah之外的其他文字"即可填充" PDF的软件到以下(x,y)坐标...;或
  • 更简便的方法:PDF规范已经允许构造"fields",并且可以填写这些字段;这样,我只写了写着将文本摘录 blah 添加到名为* address_value * ..."的字段中的代码,等等.
  • Harder Way: It is possible to scan a paper document, turn it into a PDF, and then have software that "fills out" the PDF simply by saying "add text except blah to the following (x,y) coordinates..."; or
  • Easier Way: PDF specification already allows for the construct of "fields" that can be filled out; this way I just write code that says "add text excerpt blah to the field called *address_value*...", etc.

所以我的第一个问题是:我要面对两种途径中的哪一种? PDF是否具有字段"的概念,还是需要通过告诉PDF库将数据放置在何处的像素坐标来填写"这些文档?

So my first question is: which of the two avenues am I facing? Does PDF have a concept of "fields" or do I need to "fill out" these documents by telling the PDF library the pixel coordinates of where to place data?

第二,我显然需要一个开放源代码(和Java)库来执行此操作. iText似乎是一个不错的开始,但是我听说它可能很难使用.任何人都可以在这里提出一些想法或一般建议吗?预先感谢!

Second, I obviously need an open source (and Java) library to do this. iText seems to be a good start but I've heard it can be difficult to work with. Can anyone lend some ideas or general recommendations here? Thanks in advance!

推荐答案

您可以使用FDF(表单数据格式)技术轻松地将数据合并到PDF的字段中.

You can easily merge data into PDF's fields using the FDF(Form Data Format) technology.

Adob​​e提供了一个用于执行此操作的库: Acrobat表单数据格式(FDF)工具包

Adobe provides a library to do that : Acrobat Forms Data Format (FDF) Toolkit

也可以使用 Apache PDFBox 来做到这一点.

Also Apache PDFBox can be used to do that.

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

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