I could see the empty fields all the time with iText, but I can see them when I open using manually using Adobe Acrobat Reader DC
com.lowagie.text.pdf.PdfReader reader = new com.lowagie.text.pdf.PdfReader(
new PRInputStream(dataFile));
com.lowagie.text.pdf.AcroFields af = reader.getAcroFields();
System.out.println("Field Names:" + af.getFields());
With Static PDF generated by the same software is working fine.
Expected records : 1
Actual : 0
Please find the sample PDF file https://forums.adobe.com/servlet/JiveServlet/download/2051245-11361/ExpandingTextBox.pdf
With the below snippet
com.lowagie.text.pdf.AcroFields af = reader.getAcroFields();
System.out.println("Field Names:"+af.getXfa().getTemplateSom().getName2Node().toString());
I could see
Field Names:{form1[0].#subform[0].TextFieldContainer[0].TextField1[0]=[field: null]}
but not the actual field names.
The below code is able to extract the field names from the form.
String fieldName = form.getXfa().getDatasetsNode().getFirstChild().getFirstChild().getFirstChild().getLocalName();
String str = form.getXfa().getDatasetsNode().getFirstChild().getFirstChild().getFirstChild().getTextContent();
String SiblingName = form.getXfa().getDatasetsNode().getFirstChild().getFirstChild().getFirstChild().getNextSibling().getLocalName();
String SiblingValue = form.getXfa().getDatasetsNode().getFirstChild().getFirstChild().getFirstChild().getNextSibling().getTextContent();
System.out.println("Field Name:"+fieldName);
System.out.println("Field Value:"+str);
System.out.println("Sibling Name:"+SiblingName);
System.out.println("Sibling Value:"+SiblingValue);
//Set the values back to form
form.getXfa().getDatasetsNode().getFirstChild().getFirstChild().getFirstChild().setTextContent("Updated: Content for First Field");
String updatedValue = form.getXfa().getDatasetsNode().getFirstChild().getFirstChild().getFirstChild().getTextContent();
System.out.println("Field Value:"+updatedValue);
and we could see the correct field and values and i could set the values back to the form didn't try to generate the form back however that would work.
and this usecase worked with all versions of itext (worked with 2.1.7 also)