3
我有以下封面。我需要爲許可證持有者,日期添加值,並使用其他文本填寫。這怎麼可以使用iText完成。任何幫助表示讚賞。 iText動態添加值到PDF封面中的佔位符
我有以下封面。我需要爲許可證持有者,日期添加值,並使用其他文本填寫。這怎麼可以使用iText完成。任何幫助表示讚賞。 iText動態添加值到PDF封面中的佔位符
首先,您需要創建一個表單,作爲所有許可證文檔的模板。 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
正如你看到的,代碼非常簡單。對於那些花時間閱讀文檔的人來說,所有這些都非常有用。也許你也可以看一下official web site標題爲Interactive forms的部分。
非常感謝。這正是我想要做的。 :) –