Splitting a PDF into multiple pages

I needed to split a PDF file into multiple files with one page per file.

#!/usr/bin/perl

use PDF::API2;

$pdf = PDF::API2->new;
$pdf = PDF::API2->open($ARGV[0]);
$pagecount = $pdf->pages;
for(my $i=0; $i< $pagecount; $i++) {
my $newpdf = PDF::API2->new;
$newpdf->importpage($pdf, $i, 1);
print “Saving $ARGV[0].$i\n”;
$newpdf->saveas($ARGV[0] . “.$i”);
}

3 Responses to “Splitting a PDF into multiple pages”

  1. Des Traynor says:

    Excellent stuff, thats handy Aidan.
    I suppose I’ll provide the converse…

    https://www.cs.tcd.ie/Shane.OConchuir/Misc/MergingPDFs.html

  2. vishal says:

    and if you want to convert pdf’s into handout form:
    ———————————————-
    #!/bin/sh

    outFile=`echo $1 | sed -e ‘s/\.pdf$//’`
    pdftops -level2sep $1 – | psnup -pletter \
    -d -6 -b1 -l -m3 | ps2pdf – $outFile”_handout.pdf”
    ————————————————-
    enjoy.

  3. Xeraan says:

    In case you don’t know perl, you can just print each page separate using a pdf-printer.

Leave a Reply