To fill in the fields with data, you can use the getField() method to get a field by field name and then use the setValue() method to set the data. To set values in combo boxes and list fields, use values from the field’s export options and not the display options. To save the PDF document, you need to call the save method. This sample code uses Qoppa’s PDF library jPDFFields.

// open the PDF form
PDFFields pdfFields = new PDFFields ("C:/form01.pdf", null); 
 
// setting value in text fields
((TextField) pdfFields.getField("LastName")).setValue("Smith"); 
((TextField) pdfFields.getField("FirstName")).setValue("Maggie");
 
// setting the Married check box's value to "M" (box is checked)
((CheckBoxField) pdfFields.getField("Married")).setValue("M");
 
// setting gender radio button's value to "Female"
((RadioButtonGroupField) pdfFields.getField("Gender")).setValue("Female");
 
// setting combo box to "US"
((ComboField) pdfFields.getField( "Country")).setValue("US");
 
// Setting list field' values to Kroger, Publix
((ListField) pdfFields.getField( "Supermarkets")).setValue(new Vector(new String[]{ "Kroger", "Publix"}));
 
// save PDF document
pdfFields.saveDocument("C:/form01.pdf", null);