If your form is based on AcroForm technology, you can use iText to fill it out like this:
PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); AcroFields form = stamper.getAcroFields(); form.setField(key, value); stamper.setFormFlattening(true); stamper.close(); reader.close();
In this snippet,
src is the source of a PDF file (could be a path to a file, could be a
dest is the path to the resulting PDF. The
key corresponds with the name of a field in your template. The
value corresponds with the value you want to fill in. If you want the form to keep its interactivity, you need to remove the line
stamper.setFormFlattening(true); otherwise all form fields will be removed, resulting in a flat PDF.