作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
最佳答案
首先,您需要创建一个表单,作为您所有许可文件的模板。 Chapter 6 of "iText in Action" 的第 5.3.5 节(可以免费下载的一章)解释了如何使用 OpenOffice 创建这样的表单,但是有许多替代方法可以做到这一点。我使用 Adobe Acrobat 创建了这样一个表单:CertificateOfExcellence.pdf
我突出显示了这些字段,以便您可以看到我添加它们的位置。有四种:
现在我可以轻松填写表格(参见 FillForm ):
public void manipulatePdf(String src, String dest) throws DocumentException, IOException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields form = stamper.getAcroFields();
form.setField("course", "Copying and Pasting from StackOverflow");
form.setField("name", "Some dude on StackOverflow");
form.setField("date", "April 10, 2016");
form.setField("description",
"In this course, people consistently ignore the existing documentation completely. "
+ "They are encouraged to do no effort whatsoever, but instead post their questions "
+ "on StackOverflow. It would be a mistake to refer to people completing this course "
+ "as developers. A better designation for them would be copy/paste artist. "
+ "Only in very rare cases do these people know what they are actually doing. "
+ "Not a single student has ever learned anything substantial during this course.");
stamper.setFormFlattening(true);
stamper.close();
}
生成的 PDF 如下所示:certificate.pdf
如您所见,代码非常简单。对于那些花时间阅读文档的人来说,所有这些都有很好的记录。也许您还可以查看标题为 Interactive forms 的部分在 official web site 上.
关于java - iText 为 PDF 封面中的占位符动态添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36523371/
我是一名优秀的程序员,十分优秀!