Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Filling out PDF forms with data from DBI?

by mercutio_viz (Scribe)
on Jun 24, 2006 at 07:06 UTC ( [id://557361]=note: print w/replies, xml ) Need Help??


in reply to Re: Filling out PDF forms with data from DBI?
in thread Filling out PDF forms with data from DBI?

It looks like L~R is right on the money with CAM::PDF. I've spent a lot of time with PDF::API2 but I think that CAM::PDF is better suited for this task. In the case of of the aforementioned W-9 form, with its non-descript field names, I wrote an inelegant-but-useful piece of code that helps to identify the actual field locations:

#!/usr/bin/perl # pdf-filler-test.pl use strict; use warnings; use CAM::PDF; # my $infile = 'fw9.pdf'; my $outfile = 'modified_fw9.pdf'; my $pdf = CAM::PDF->new($infile) or die 'wtf'; my @FIELDS = $pdf->getFormFieldList(); # foreach ( @FIELDS ) { my $fieldnum = $_; $fieldnum =~ s/f1-//; $pdf->fillFormFields($_ => $fieldnum); } $pdf->cleanoutput($outfile);

This revealed that each digit in the SSN and tax ID number fields is actually a form field. I would assume that Randal would need to analyze each form so as to know which fields are what, and then create the appropriate mapping from DBI fields to PDF form fields.

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. To add a check mark on "Corporation" you could just do this:

#!/usr/bin/perl use strict; use warnings; use PDF::API2; # location of "Corporation" check box is: # 173 pts from left, 660 pts from bottom my $infile = 'modified_fw9.pdf'; my $outfile = 'modified_check_corp_box_fw9.pdf'; my $pdf = PDF::API2->open($infile); my $page = $pdf->openpage('1'); my $text = $page->text(); my $font = $pdf->corefont('Helvetica'); # prepare text object $text->font($font,11); # Set font to Helvetica, 11pt $text->fillcolor("#000000"); # This is black $text->translate(173,660); # Text start location for Corp chk box $text->text("X"); # Print "X" at 173,660 $pdf->saveas($outfile); $pdf->end;

These are just some thoughts. Please let us know what you eventually come up with. I'm curious to see how this looks in a production environment.

-MC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-16 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found