Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

How to check CheckBoxes and RadioButtons

Help
Leitender
2011-04-21
2013-05-28
  • Leitender
    Leitender
    2011-04-21

    Hello,

    how can I check CheckBoxes and RadioButtons?

    I tried

    PDAcroForm form = getDoc().getAcroForm();
    PDAcroFormField formField = form.getField("MyCheckBox");
    PDAFButtonField checkbox = (PDAFButtonField) formField;
    checkbox.setValueString("On");

    but MyCheckBox is not checked. What is wrong?

    The PDF document is created with Acrobat 9 Pro.

     
  • mtraut
    mtraut
    2011-04-26

    PDF forms have a lot of caveats and very few inherent logic. In this case you should at least:

    - verify that "On" is one of the valid states in your field (getAppearanceStates in the annotation)
    - verify that every state has a valid appearance stream (this is what gets rendered)
    - verify that you set the value in the correct object. A field MAY be separated in field and annotation AND a field may have multiple annotations and as such a hierarchy. In short, set the value in the top level (field) object and ensure that no other value entry is active in the child elements.

    The result (if a single object) should look like the example from the PDF spec

    << /FT /Btn
    /T ( Urgent )
    /V /Yes
    /AS /Yes
    /AP << /N << /Yes 2 0 R /Off 3 0 R>>
    >>