As easy as 1, 2, 3...
Each type of form field has different setters depending on its nature.
In the example above, the form field named "Text" is a text field.
Updating its value is as simple as the following code:
// Update the form field:
((TextField) myField).setValue("My Text Field new value");

When working with template documents, it is common to leave
them unchanged and to save the updated version to a new
destination:
// Save the modified document to a new location:
doc.saveAs("generatedDocument.pdf");
doc.close();