Fill checkbox in iText

I am trying to modify an existing PDF using iText. My code is currently editing text fields nicely, but I can’t tag or uncheck it.

PdfReader reader = new PdfReader(INPUTFILE); int n = reader.getNumberOfPages(); PdfStamper filledOutForm = new PdfStamper(reader, new FileOutputStream("WrittenForm.pdf")); AcroFields fields = filledOutForm.getAcroFields(); //not working fields.setField("checkbox", "On"); //working fields.setField("textfield1", "infinite road"); fields.setField("textfield2", "jayboy"); filledOutForm.close(); 

Any ideas?

DECIDE:

  String states[] = fields.getAppearanceStates("checkbox"); //prints array values - returns 'yes, no' System.out.println(Arrays.toString(states)); 
+4
source share
3 answers

When I saw here , you need to check the available states using:

 String[] states = fields.getAppearanceStates("checkbox"); 

And then set the state according to the parameters in this String[]

+9
source

While

 fields.getAppearanceStates("checkbox"); 

usually returns the correct value, in some of my checkboxes for some reason this returns an empty array. Looking at the form in Acrobat Pro, I found that the correct line to send to setField is called the Export Value on the Options tab of the field properties. You can also change it there.

0
source
 filledOutForm.setFormFlattening(true); 
-2
source

Source: https://habr.com/ru/post/1395067/


All Articles