Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ziggy (25)

  (email not shown publicly)
AOL IM: ziggyatpanix (Add Buddy, Send Message)

Journal of ziggy (25)

Monday December 19, 2005
05:22 PM

PDF Hacks

[ #28063 ]

I have a handful of PDFs I want to combine into a single PDF. I remember trying to solve this problem on OS X a few years ago, and found no (obvious) native tools to use, and a very few open source tools that could do the job. Eventually, I found some little open source applet written in RealBasic that worked the one time I needed it; I don't remember what it was, and probably never used it again.

Of course, that's totally lame. A real solution would involve something from CPAN and a couple of lines of Perl. For example, something like this:

#!/usr/bin/perl -w
use strict;
use PDF::Reuse;
my $output = shift(@ARGV);
prDoc({file => $_}) foreach (@ARGV);

PDF::Reuse has lots of other features, including picking and choosing which pages of a PDF to reuse and merge. But for joining a whole mess of PDFs together into a single file, this works wonderfully.

Thanks, Lars!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • OK, it's not really a "native" solution either, but if you've got a tex distribution (say "teTeX") kicking around on the system there's a similarly nice solution via:

    texexec --pdfarrange --result all.pdf file*.pdf

    (or even using ghostscript

    gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf


    If you want more control over importing certain pages you can use the pdfpages package in latex; just run the following file (call it all.tex or whatever) through latex:

  • and thank you for posting this, very useful
  • Cool. Here's another solution

    % cpan install CAM::PDF
    % file1.pdf file2.pdf out.pdf

    or almost equivalently:

    use CAM::PDF;
    my $doc1 = CAM::PDF->new(shift);
    my $doc2 = CAM::PDF->new(shift);

    -- Chris

    P.S. I'm the author of CAM::PDF
  • Very cool, I was just thinking about this the other day. I found a different solution (I had the originals and combined into one document first).