FormCreation.java(iText 5)

在这个 iText 5 示例中,我们将创建一个文本字段,然后将其添加到 PDF:

StackOverflow 文档

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