FormFilling.java(iText 5)

在这个 iText 5 示例中,我们将更改文本字段的属性和值:

StackOverflow 文档

public void manipulatePdf(String src, String dest) throws DocumentException, IOException {
    PdfReader reader = new PdfReader(src);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
    AcroFields fields = stamper.getAcroFields();
    fields.setFieldProperty("text", "textcolor", BaseColor.BLUE, null);
    fields.setFieldProperty("text", "bordercolor", BaseColor.RED, null);
    fields.setFieldProperty("text", "fontsize", 14, null);
    fields.setField("text", "Field Text");
    stamper.close();
    reader.close();
}

资料来源: developers.itextpdf.com