Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

  • $ff_obj->{value}->{value}->{DV}->{value} = checkThisBox() ? 'Yes' : 'Off';
  • $ff_obj->{value}->{value}->{V}->{value} = checkThisBox() ? 'Yes' : 'Off';

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-18 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found