Just came across this while searching for same--I'm using the Federal W4 form, and it's set up similarly.

First of all, trying to modify the object returned by getFormFieldDict() isn't going to get you anywhere. It says right in the docs that it's supposed to be treated as a read-only construct; it's not really a pointer to the dictionary object.

Second, after much futzing around, I figured out that something like this works (snipping from your code above):

foreach my $field ( @FIELDS ) { if ($field =~ /^c/) { my $ff_obj = $pdf->getFormField($field); $ff_obj->{value}->{value}->{AS}->{value} = checkThisBox() ? 'Y +es' : 'Off'; } else { $pdf->fillFormFields($field => $field); } }

I found that when a checkbox is checked manually, there are three properties that different from one that's not checked:

  1. $ff_obj->{value}->{value}->{AS}
  2. $ff_obj->{value}->{value}->{DV}
  3. $ff_obj->{value}->{value}->{V} (the one you found)

However, changing the value of the 'value' key on 'DV' and 'V' didn't seem to do anything for me. That is, these statements didn't seem to do anything:

Reason being . . . 'DV' and 'V' stand for 'Default Value' and 'Value', respectively. In the inner workings of a PDF form, these values are useful for processing and whatnot, but unlike in the DOM or something like that, the *value* of the checkbox and whether an actual checkmark appears in that box are not necessarily the same (if you're setting them programmatically).

Hence, the 'AS' key, which stands for 'Appearance State'. Setting the value AS's 'value' key thus places a checkmark there.

So, depending on what you're doing with this form, you may also want to set 'DV' and/or 'V' the same way, like if you're actually presenting it as a web form complete with some Javascript or other logic. In my case, I'm just filling the forms in with data from a database and sending them straight to the printer, so I don't care about the actual checkbox values.

Hope this helps.


In reply to Re: Filling PDF Form Checkboxes by jwagon
in thread Filling PDF Form Checkboxes by steve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.