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


In reply to Re^2: Filling out PDF forms with data from DBI? by mercutio_viz
in thread Filling out PDF forms with data from DBI? by merlyn

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.