Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge PDF files with Perl?

Tags:

merge

pdf

perl

Using Perl, how can I combine or merge the sample PDF files into a single PDF file?

like image 207
Anil Avatar asked Jan 07 '09 05:01

Anil


3 Answers

CAM::PDF can do this quite easily, and has a simple command-line front end to help. Note: I'm the author of that library. Example:

appendpdf.pl file1.pdf file2.pdf outfile.pdf

From the SYNOPSIS section of the perldoc:

my $anotherpdf = CAM::PDF->new('test2.pdf');
$pdf->appendPDF($anotherpdf);
like image 54
Chris Dolan Avatar answered Sep 25 '22 12:09

Chris Dolan


Why do you need to do it from Perl? Chris has already mentioned CAM::PDF.

If you just need to merge them, pdftk (PDF ToolKit) works just fine. It's a simple command line:

pdftk file1.pdf file2.pdf cat output merged.pdf
like image 29
brian d foy Avatar answered Sep 25 '22 12:09

brian d foy


You can use the GhostScript utility pdf2ps to convert the PDFs into PostScript files, concatenate the PostScript files, and then use ps2pdf to convert the result back into a PDF.

like image 30
Adam Rosenfield Avatar answered Sep 23 '22 12:09

Adam Rosenfield