FormCreation.java(iText 5)
在這個 iText 5 示例中,我們將建立一個文字欄位,然後將其新增到 PDF:
public void manipulatePdf(String src, String dest) throws DocumentException, IOException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
TextField tf = new TextField(stamper.getWriter(),
new Rectangle(110, 780, 180, 806), "text");
tf.setBorderColor(BaseColor.BLUE);
tf.setBorderWidth(2);
tf.setTextColor(BaseColor.RED);
tf.setFontSize(12);
tf.setText("Text field");
PdfFormField field = tf.getTextField();
stamper.addAnnotation(field, 1);
stamper.close();
reader.close();
}
資料來源: developers.itextpdf.com