2

I need to fill in a single PDF template multiple times and concat the results. When I say multiple, I mean up to a few hundred times, potentially over one thousand.

I can do this with pdftk fill_form, one by one, and then use pdftk cat. We can parallelize this fairly easily.

I'm curious if this is the only option, or if there is a piece of software (Linux + OSX, command line) that will allow me to say "take this template, and these sets of fields, fill out this form, and concat the files" so I can avoid doing every one individually. Then again, if something does exist, but it's not any faster than just doing the fork parallelization method, then it's probably not worth it.

Daniel Huckstep
  • 5,368
  • 10
  • 40
  • 56

1 Answers1

1

My Perl library CAM::PDF can do this. The form filling is a bit weak (it doesn't support checkboxes, for example) but the concatenation works great.

#perl -w                                                                            
use strict;
use CAM::PDF;

my $infile = 'in.pdf';
my $outfile = 'out.pdf';
my @fills = (
   { name => 'John' },
   { name => 'Fred' },
);

my $pdf = CAM::PDF->new($infile) or die $CAM::PDF::errstr;
for my $i (0 .. @fills-1) {
   my $filledPDF = $i == 0 ? $pdf : CAM::PDF->new($infile);
   $filledPDF->fillFormFields(%{$fills[$i]});
   if ($i > 0) {
      $pdf->appendPDF($filledPDF);
   }
}
$pdf->cleanoutput($outfile) or die;
Chris Dolan
  • 8,905
  • 2
  • 35
  • 73