FormCreation.java(iText 7)

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

StackOverflow 文档

public void manipulatePdf(String src, String dest) throws IOException {
    PdfReader reader = new PdfReader(src);
    PdfDocument pdf = new PdfDocument(reader, new PdfWriter(dest));
    PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
    PdfFormField tf = PdfTextFormField.createText(
        pdf, new Rectangle(110, 780, 70, 26), "text", "Text Field")
        .setBorderColor(Color.BLUE)
        .setBorderWidth(2)
        .setColor(Color.RED)
        .setFontSize(12);
    form.addField(tf);
    pdf.close();
}

资料来源: developers.itextpdf.com