How to check CheckBoxes and RadioButtons

  • Leitender

    Leitender - 2011-04-21


    how can I check CheckBoxes and RadioButtons?

    I tried

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

    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>>

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks