Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am essentially working toward he same end posted by merlyn some time ago in Filling out PDF forms with data from DBI?. The reply posted in Re^2: Filling out PDF forms with data from DBI? is very helpful, but indicates that for checkboxes:
On this particular form I noticed that the check boxes were not form fields. Randal, does your client require a check mark on the document, e.g. for "sole proprietor" or "Corporation?" The only reason I ask is because I don't see an easy means to add a check mark using CAM::PDF. PDF::API2 or PDF::Reuse can do that easily. However, they don't have the easy interface into forms the way CAM::PDF does. It might be a bit of a kludge, but running through CAM::PDF to fill in the forms and then running through PDF::API2 to add any checkmarks (or any kind of glyphs or graphics) would be pretty easy.

I would like very much to avoid this method of populating checkboxes because it effectively breaks the PDF form -- that is to say that once something is printed over the top of a checkbox it can no longer be operated as a checkbox.

I am not certain if it is because CAM::PDF or the PDF format has changed significantly since then, but getFormFieldList within CAM::PDF actually does return checkbox keys which are (to some degree) accessible through the same CAM::PDF object.

I have used CAM::PDF to access the dictionary objects for these checkboxes using the W-9 at http://www.irs.gov/pub/irs-pdf/fw9.pdf as a test case. I have compared the objects for each checkbox from a form that is saved with and without the boxes checked. The checked boxes appear like so (the following example is from the first checkbox in the form, using Data::Dumper):
$VAR1 = { 'FT' => bless( { 'value' => 'Btn', 'gennum' => '0', 'type' => 'label', 'objnum' => '31' }, 'CAM::PDF::Node' ), 'DA' => bless( { 'value' => '/ZaDb 9.0 Tf 1.000 0.660 0.000 +0.180 k ', 'gennum' => '0', 'type' => 'string', 'objnum' => '31' }, 'CAM::PDF::Node' ) };
and the checked boxes seem to have a small portion added:
$VAR1 = { 'FT' => bless( { 'value' => 'Btn', 'gennum' => '0', 'type' => 'label', 'objnum' => '31' }, 'CAM::PDF::Node' ), 'DA' => bless( { 'value' => '/ZaDb 9.0 Tf 1.000 0.660 0.000 +0.180 k ', 'gennum' => '0', 'type' => 'string', 'objnum' => '31' }, 'CAM::PDF::Node' ), 'V' => bless( { 'gennum' => '0', 'value' => 'Yes', 'type' => 'label', 'objnum' => '31' }, 'CAM::PDF::Node' ) };
I have started with the following code that modifies the object to include the missing section, however I am still not seeing it in the form.
#!/usr/bin/perl # pdf-filler-test.pl use strict; use warnings; use CAM::PDF; use Data::Dumper; my $infile = 'fw9.pdf'; my $outfile = 'modified_fw9.pdf'; my $pdf = CAM::PDF->new($infile) or die "Cannot open $infile"; my @FIELDS = $pdf->getFormFieldList(); use Data::Dumper; foreach my $field ( @FIELDS ) { if ($field =~ /^c/) { my $ff_obj = $pdf->getFormField($field); my $dict = $pdf->getFormFieldDict($ff_obj); $dict->{V} = CAM::PDF::Node->new('label', 'Yes', $ff_obj->{obj +num}, $ff_obj->{gennum}); print Dumper $dict; } else { $pdf->fillFormFields($field => $field); } } $pdf->fillFormFields( 'f1_01(0)' => 'name', 'f1_02(0)' => 'test', ); $pdf->cleanoutput($outfile);
I am not sure if there is just something I am missing or if this really is not feasible, but would gladly welcome suggestions.

In reply to 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 making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-28 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found