How to set Check Box Style to "Check" using iText in existing form?
Asked Answered
T

1

6

I have PDF with acroForm that was created using Adobe Acrobat Standard DC.

There is Chekcbox field that I populate using Java iText 5. When I was creating it in Properties I set it up Check Box Style to "Check" so it will put "V" style symbol when it is checked. enter image description here

And it does really work if I open the form in Preview mode and check this CheckBox: enter image description here

But when I set this field to checked state using iText 5 it checks it is Cross: enter image description here

I can't figure out why it is changing style?

My code is simple:

void populateCheckBox(AcroFields form, String searchKey, String value) throws IOException, DocumentException {

        if (form.getFieldType(searchKey) == AcroFields.FIELD_TYPE_CHECKBOX) {

            String[] states = form.getAppearanceStates(searchKey);              
            if (ArrayUtils.contains(states, "On") && ArrayUtils.contains(states, "Off")) {
                value = (value.equals("1")) ? "On" : "Off";
                form.setField(searchKey, value);
            } 
        }
    }
Tabethatabib answered 12/1, 2018 at 2:23 Comment(0)
H
2

Late answer, but you just have to pass third boolean parameter to setField function to save default appearance

   ...
    form.setField(searchKey, value, true);
   ...
Herat answered 16/5, 2019 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.