I'm having trouble retrieving the export value for checkboxes in PDFBox. I'm using PDFBox v2.0.21. I need the export values as I need to know what each checkbox field maps to in another application.
The checkboxes have the same partial name, but different export values. An example pdf is here.
If I call "getExportValues" on the field, I get all available checkbox export options for the group of checkboxes ["a","b"]. e.g. ((PDCheckBox) field).getExportValues(); //returns ["a","b"]
Is there a way to determine which export value belongs to the current field?
If I call "getOnValue" it returns "0" (it does this for all the checkbox fields). e.g. onValue = ((PDCheckBox) field).getOnValue(); //returns "0"
It returns "0" regardless of which field I'm looking at.
If I call field.check()
it throws 'java.lang.IllegalArgumentException' exception (which I assume is because it's using "0" instead of "a" or "b".
If I call field.setValue()
with either "a" or "b" they both succeed for the field, so it's not clear what other options to try. I had attempted this approach in the hope that I could determine what export value belongs to the field I'm currently querying.
Please let me know if you have any insights into the above.
Update: after further debugging it looks like each field has 2 widgets associated with it (so if field checkbox has the same name it has multiple widgets). Adding additional checkbox to pdf results in 3 widgets associated with each fields. If I use field.getWidgets().get(1).dictionary.getCOSObject(COSName.AP).getDictionaryObject(COSName.N)
and get the key that isn't "off" (as outlined here) then it returns "1" which I assume is the index of that widgets export value (from getExportValues) however I don't see a way to determine which widget belongs to the field I'm currently looking at.
Thanks Rob