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


Example

In this iText 5 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 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();
}

Source: developers.itextpdf.com