How to set Check Box Style to “Check” using iText in existing form?

心已入冬 提交于 2019-12-07 13:32:06

问题


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.

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

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

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);
            } 
        }
    }

回答1:


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

   ...
    form.setField(searchKey, value, true);
   ...


来源:https://stackoverflow.com/questions/48218695/how-to-set-check-box-style-to-check-using-itext-in-existing-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!