I need to split the pdf document into two parts,like i have a pdf which consists 100 pages,i need to split the pdf into two parts where first part consits 10 pages and second part consists 1 to 100 pages?how to do that using php?

3 Years
Discussion Span
Last Post by sushu1209
Featured Replies
  • 1

    You'll need a tool probably. I haven't seen this done in PHP yet. Perhaps [PDFLib](http://www.pdflib.com/pdflib-cookbook/pdf-import/split-document/php-split-document/) is an option. Read More


Funny enough I'm doing a very similar thing right now. I couldn't find a solution native to the language I originally used (VBScript) by googling so what I did was create a custom ghostscript script PDF2PDF and call it from the OS shell. I'm now porting the program to PHP and was going to just use the same solution - I'd be interested to see if the geniuses here have a native PHP solution! My docs start off as BZ2 postscript, so I shell out to decompress, shell out to convert to PDF then shell out again to extract the desired pages from the PDF. ouch...

Edited by BenWard


hi ....any solution how to split pdf using php code??..any one from php in daniweb?


Ok thanks for your reply,

Am using fpdf to extract the pages,and its extracting pages for some pdf's and for some [df's its showing error as file is encrypted?

Here is my code to extract pages using fpdf.

class ConcatPdf extends FPDI {
    public $files = array();
    public function setFiles($files) {
        $this->files = $files;
    public function concat($sample) {
        foreach ($this->files AS $file) {
            $pageCount = $this->setSourceFile($file);

            for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
                $tplIdx = $this->ImportPage($pageNo);
                $s = $this->getTemplatesize($tplIdx);
                $this->AddPage($s['w'] > $s['h'] ? 'L' : 'P', array($s['w'], $s['h']));
                if ($pageNo == 1 && $sample == 1) {
                if ($pageNo == 30) {


$pdf = new ConcatPdf();
$pdf->setFiles(array("blank.pdf", "one.pdf")); 
$pdf->Output('concat.pdf', 'D'); //D-download I-view 


Any solution?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.