Sunday, August 16, 2009

Automatically fill in a PDF form with a perl script

I am using perl version 5.10, and I installed CAM::PDF (version 1.52) by using ppm.


#!/usr/bin/perl
use strict;
use warnings;
use CAM::PDF;

my $infile = input.pdf';
my $outfile = output.pdf';
my $pdf = CAM::PDF->new($infile) or die 'error';
my @FIELDS = $pdf->getFormFieldList();

foreach my $field ( @FIELDS ) {
if ($field =~ /^c/) {
my $ff_obj = $pdf->getFormField($field);
$ff_obj->{value}->{value}->{AS}->{value} = 'Yes'; #This line sets a check in the checkbox fields
}

else {
$pdf->fillFormFields($field => $field); #This line sets the value of the field to the field name.
}
}
$pdf->cleanoutput($outfile);


It seems that on adobe 1.6 files with interactive forms some of the coding is lost and when the output file is opened there is an error stating “this document enabled extended features in adobe reader. the document has been changed”

This seems to be due to incompatibilities in the version of CAM::PDF.

It works fine under older versions of pdf files.


1 comment:

  1. Hi. This service here allows you to easily edit your PDF documents.
    http://goo.gl/KEqjsI

    You can fill out PDF form, save it, fax it, and email it.

    ReplyDelete