fillFormFields multiple pages, bizarre results.

Posted on 2009-11-19 16:30:54-08 by mchineboy
fillFormFields multiple pages, bizarre results.

Maybe I'm doing this wrong, and that's quite possible. What I'm attempting is to take individual pdf forms, fill out the forms using a database, concatenate the pdfs, and then send the resulting PDF via mod_perl. So far the results are funny, like clown funny (scary and entertaining at the same time). All of the forms are produced in Acrobat 8. Adobe Reader 9: First page has most of the fields filled. Except one. remaining pages are blank and are stripped of form fields. OS-X Preview: First page, all fields are filled, remaining pages all look like the first page. Linux evince: Looks as expected. All pages are as they should be. Testing has been done in OS-X, Linux, and Windows. OS-X and Windows seem to jive, however the Linux results are cool. Now I need to convince 167,000 people that they need to ditch windows!

Anyway, the algorithm I devised works like this:

* Lookup data for person calling the webapp.

* Pull the appropriate pdf form based on the data return (these are tax forms, so they're legion).

* Fill out the page with the current row, append it to the "master pdf".

* Once all rows are complete, return the resulting PDF to the browser.

The code looks like this:

while ( my $form = $gettaxforms->fetchrow_hashref() ) { next unless -f $templates . "/" . $form->{PDFFILE}; my $nextpage; unless ( $masterpdf ) { $masterpdf = CAM::PDF->new( $templates . "/" . $form->{PDFFILE} ) or die $!, $@; } else { $nextpage = CAM::PDF->new( $templates . "/" . $form->{PDFFILE} ) or die $!, $@; } if ( $nextpage ) { $nextpage = fillForm( $fieldmaps, $form, $nextpage ); $masterpdf->appendPDF($nextpage); } else { $masterpdf = fillForm( $fieldmaps, $form, $masterpdf ); } } my $pdf = $masterpdf->toPDF(); $r->set_content_length(length($pdf)); $|--; print $pdf; $|++; $masterpdf = undef;

fillForm looks like this:

sub fillForm { my ( $fieldmaps, $form, $page ) = @_; my @fields = $page->getFormFieldList(); my %fields; foreach (@fields) { /alternate name/i && next; my $thisfield = $fieldmaps->{ $form->{RETURNTYPE} }->{ $form->{TAXYEAR} }->{$_}; unless ( $thisfield ) { $fields{$_} = $_ . "UNKNOWN FIELD IN MAPPER!!"; next; } if ( $thisfield->{DEFAULT} ) { $thisfield->{DEFAULT} =~ s/\\n/\n/g; $fields{$_} = $thisfield->{DEFAULT}; } else { warn $form->{ $thisfield->{COLUMN} }; if ( $thisfield->{FORMAT} eq 'number' ) { $fields{$_} = sprintf( '%0.02f', int( $form->{ $thisfield->{COLUMN} } ) / 100); $fields{$_} = '' if $fields{$_} eq '0.00'; } elsif ( $thisfield->{FORMAT} eq 'string' ) { $fields{$_} = uc( $form->{ $thisfield->{COLUMN} } ); } elsif ( $thisfield->{FORMAT} eq 'ctstzip' ) { $fields{$_} = uc( $form->{PAYEECITY} . " " . $form->{PAYEESTATE} . " " . $form->{PAYEEZIPCODE} ); } elsif ( $thisfield->{FORMAT} eq 'taxid' ) { $fields{$_} = substr( $form->{PAYEESTIN}, 0, 3 ) . '-' . substr( $form->{PAYEESTIN}, 3, 2 ) . '-' . substr( $form->{PAYEESTIN}, 5, 4 ); } else { $fields{$_} = $form->{ $thisfield->{COLUMN} }; } } } $page->fillFormFields({background_color => 'none'}, %fields); return $page; }

Any ideas? Is this a bug? Should I be approaching this differently?

Direct Responses: Write a response