PHP code example of warlog7997 / pdfsplit

1. Go to this page and download the library: Download warlog7997/pdfsplit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

warlog7997 / pdfsplit example snippets


use Subash\PhpPdf\PhpPdf;

// Save to directory — produces page_1.pdf, page_2.pdf, ...
PhpPdf::load('document.pdf')
    ->splitter()
    ->splitToDirectory('/output/dir/');

// Or get binary strings (store in DB, upload to S3, etc.)
$pages = PhpPdf::load('document.pdf')
    ->splitter()
    ->split();
// [1 => '<pdf binary>', 2 => '<pdf binary>', ...]

// Extract pages 1 and 3
$pdfBinary = PhpPdf::load('document.pdf')->extract([1, 3]);
file_put_contents('extracted.pdf', $pdfBinary);

// Extract pages 1 through 5
$pdfBinary = PhpPdf::load('document.pdf')->extractRange(1, 5);
file_put_contents('pages1to5.pdf', $pdfBinary);

PhpPdf::merger()
    ->add('file1.pdf')
    ->add('file2.pdf')
    ->save('merged.pdf');

$pdfBinary = file_get_contents('document.pdf');
$pdf = PhpPdf::loadData($pdfBinary);
echo $pdf->getPageCount();