1.11M Members

Split a pdf using php code

 
0
 

Hi,

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?

 
0
 

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...

 
0
 

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

 
1
 

You'll need a tool probably. I haven't seen this done in PHP yet.

Perhaps PDFLib is an option.

 
0
 

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.

<?php
require_once('fpdf.php');
require_once('fpdi.php');
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']));
                $this->useTemplate($tplIdx);
                if ($pageNo == 1 && $sample == 1) {
                    break;
                }
                if ($pageNo == 30) {
                    break;
                }
            }
        }
    }

}

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

?>

Any solution?

You
Post:
Start New Discussion
Tags Related to this Article