views:

619

answers:

4

Can anybody point me towards a PHP library or script that would allow me to split a pdf consisting of multiple pages into separate files, each containing 1 page. The PDFLib documentation doesn't appear to allow this and Google hasn't been particularly helpful.

I could possibly also use Perl, but it would be very inconvenient to do so.

+6  A: 

I have used PDF::Reuse. It makes it so easy it is not even funny. Here is the relevant snippet from one of my scripts:

while ( my $line = <$page_list> ) {
    chomp $line;
    my ($class, $drug, $page) = split ' ', $line;

    my $dir = canonpath( catfile $OUTPUT_DIR, $class );
    mkdir $dir unless -e $dir;

    my $target = canonpath( catfile $dir, "$drug.pdf" );

    prFile( $target );
    prCompress( 1 );
    prDoc( $INPUT_PDF, $page, $page + 1 );
    prEnd();
}
Sinan Ünür
+2  A: 

See PDF::Extract CPAN module for Perl.

Alexandr Ciornii
A: 

Does TCPDF do what you want? It is native PHP.

drewk
+3  A: 

It's not perl or php, but pdftk easily does this and much more.

runrig