Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Filling PDF Form Checkboxes

by jwagon (Initiate)
on Jun 17, 2009 at 01:57 UTC ( [id://772195]=note: print w/replies, xml ) Need Help??


in reply to Filling PDF Form Checkboxes

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://772195]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-24 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found