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.
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();
}
It's not perl or php, but pdftk easily does this and much more.
See PDF::Extract CPAN module for Perl.
Does TCPDF do what you want? It is native PHP.
I would vote for using PDFTk even if you choose to call it PDFTk from PHP. It has excellent track record of how to do this. The following example shows how to split your PDF with PDFTk
pdf2json.exe Paper.pdf -enc UTF-8 -compress -split 10 Paper.pdf_%.js
(example taken from this url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With