I'm using iText library to generate pdf file based on template. But when I try to set checkbox field it won't filled. Class is here:
public class MainClass {
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader("pdf/fw9_template.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("test.pdf"));
AcroFields form = stamper.getAcroFields();
String states[] = form.getAppearanceStates("topmostSubform[0].Page1[0].FederalClassification[0].c1_1");
System.out.println(states);
for (Iterator i = form.getFields().keySet().iterator(); i.hasNext(); ) {
String key = (String) i.next();
System.out.print(key + " : ");
switch(form.getFieldType(key)) {
case AcroFields.FIELD_TYPE_CHECKBOX:
System.out.println("Checkbox");
break;
case AcroFields.FIELD_TYPE_COMBO:
System.out.println("Combobox");
break;
case AcroFields.FIELD_TYPE_LIST:
System.out.println("List");
break;
case AcroFields.FIELD_TYPE_NONE:
System.out.println("None");
break;
case AcroFields.FIELD_TYPE_PUSHBUTTON:
System.out.println("Pushbutton");
break;
case AcroFields.FIELD_TYPE_RADIOBUTTON:
System.out.println("Radiobutton");
break;
case AcroFields.FIELD_TYPE_SIGNATURE:
System.out.println("Signature");
break;
case AcroFields.FIELD_TYPE_TEXT:
System.out.println("Text");
break;
default:
System.out.println("?");
}
}
form.setField("topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0]", "true");
stamper.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Program output:
null
topmostSubform[0].Page1[0].EmployerID[0].f1_14[0] : Text
topmostSubform[0].Page1[0].FederalClassification[0].f1_4[0] : Text
topmostSubform[0].Page1[0].f1_9[0] : Text
topmostSubform[0].Page1[0].f1_10[0] : Text
topmostSubform[0].Page1[0].FederalClassification[0].c1_1[1] : Checkbox
topmostSubform[0].Page1[0].f1_2[0] : Text
topmostSubform[0].Page1[0].EmployerID[0].f1_15[0] : Text
topmostSubform[0].Page1[0].SSN[0].f1_12[0] : Text
topmostSubform[0].Page1[0].SSN[0].f1_13[0] : Text
topmostSubform[0].Page1[0].Address[0].f1_8[0] : Text
topmostSubform[0].Page1[0].Address[0].f1_7[0] : Text
topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0] : Checkbox
topmostSubform[0].Page1[0].FederalClassification[0].c1_1[2] : Checkbox
topmostSubform[0].Page1[0].FederalClassification[0].c1_7[0] : Checkbox
topmostSubform[0].Page1[0].FederalClassification[0].c1_1[4] : Checkbox
topmostSubform[0].Page1[0].FederalClassification[0].c1_1[3] : Checkbox
topmostSubform[0].Page1[0].f1_1[0] : Text
topmostSubform[0].Page1[0].FederalClassification[0].c1_1[5] : Checkbox
topmostSubform[0].Page1[0].SSN[0].f1_11[0] : Text
topmostSubform[0].Page1[0].FederalClassification[0].f1_3[0] : Text
topmostSubform[0].Page1[0].Exemptions[0].f1_6[0] : Text
topmostSubform[0].Page1[0].Exemptions[0].f1_5[0] : Text
I don't understand why the method getAppearanceStates() returns 'null', when we can see checkboxes in the output. Also checkbox doesn't filled in a result pdf file.
Can anybody help me to resolve this issue?
Thanks in advance, Sergey
Aucun commentaire:
Enregistrer un commentaire