Take the 2-minute tour ×

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

share|improve this question
add comment

3 Answers

up vote 13 down vote accepted

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:

share|improve this answer
Accept this answer. –  Murali VP Jan 29 '10 at 2:14
There was a bug in CAM::PDF prior to April 2011 where the append might be corrupt if file2.pdf was larger than file1.pdf. The workaround was to prepend (appendpdf.pl -p) file1.pdf to file2.pdf. This is fixed in CAM::PDF 1.54. –  Chris Dolan Apr 7 '11 at 7:18
add comment

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
share|improve this answer
add comment

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.

share|improve this answer
Why the downvote? At least leave a reason... –  Adam Rosenfield Jan 7 '09 at 6:21
I think it's because your solution doesn't use Perl. –  Nathan Fellman Jan 7 '09 at 19:00
Just because it's not a native Perl solutions doesn't mean it isn't any good. Perl can very easily invoke other utilities via the shell. –  Adam Rosenfield Jan 8 '09 at 2:10
add comment

Your Answer


