itext Forms: iText 5 vs iText 7 FormCreation.java (iText 7)


Example

In this iText 7 example, we'll create a text field and we'll add it to a PDF:

enter image description here

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();
}

Source: developers.itextpdf.com