public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf') {
        if (!isset($this->_files) || !is_array($this->_files)) {
            throw new Exception("No PDFs to merge.");
        }

        $fpdi = new FPDI;

        // merger operations
        /* @var $file PdfObject */
        foreach ($this->_files as $file) {
            $filename = $file->path;
            $filepages = $file->pages;

            $count = $fpdi->setSourceFile($filename);

            //add the pages
            if ($filepages == 'all') {
                for ($i = 1; $i <= $count; $i++) {
                    $template = $fpdi->importPage($i);
                    $size = $fpdi->getTemplateSize($template);

                    $fpdi->AddPage($file->getOrientationCode(), array($size['width'], $size['height']));
                    $fpdi->useTemplate($template);
                }
            } else {
                foreach ($filepages as $page) {
                    if (!$template = $fpdi->importPage($page)) {
                        throw new Exception("Could not load page '$page' in PDF '$filename'. Check that the page exists.");
                    }
                    $size = $fpdi->getTemplateSize($template);

                    $fpdi->AddPage($file->getOrientationCode(), array($size['w'], $size['h']));
                    $fpdi->useTemplate($template);
                }
            }
        }

        //output operations
        $mode = $this->_switchmode($outputmode);

        if ($mode == 'S') {
            return $fpdi->Output($outputpath, 'S');
        } else {
            if ($fpdi->Output($outputpath, $mode) == '') {
                return true;
            } else {
                throw new Exception("Error outputting PDF to '$outputmode'.");
                return false;
            }
        }
    }
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf') {
        if (!isset($this->_files) || !is_array($this->_files)) {
            throw new Exception("No PDFs to merge.");
        }

        $fpdi = new FPDI;

        // merger operations
        /* @var $file PdfObject */
        foreach ($this->_files as $file) {
            $filename = $file->path;
            $filepages = $file->pages;

            $count = $fpdi->setSourceFile($filename);

            //add the pages
            if ($filepages == 'all') {
                for ($i = 1; $i <= $count; $i++) {
                    $template = $fpdi->importPage($i);
                    $size = $fpdi->getTemplateSize($template);

                    $fpdi->AddPage($file->getOrientationCode(), array($size['width'], $size['height']));
                    $fpdi->useTemplate($template);
                }
            } else {
                foreach ($filepages as $page) {
                    if (!$template = $fpdi->importPage($page)) {
                        throw new Exception("Could not load page '$page' in PDF '$filename'. Check that the page exists.");
                    }
                    $size = $fpdi->getTemplateSize($template);

                    $fpdi->AddPage($file->getOrientationCode(), array($size['w'], $size['h']));
                    $fpdi->useTemplate($template);
                }
            }
        }

        //output operations
        $mode = $this->_switchmode($outputmode);

        if ($mode == 'S') {
            return $fpdi->Output($outputpath, 'S');
        } else {
            if ($fpdi->Output($outputpath, $mode) == '') {
                return true;
            } else {
                throw new Exception("Error outputting PDF to '$outputmode'.");
                return false;
            }
        }
    }
public function merge ( $ outputmode = 'browser' , $ outputpath = 'newfile.pdf' ) { if ( ! isset ( $ this -> _files ) || ! is_array ( $ this -> _files ) ) { throw new Exception ( "No PDFs to merge." ) ; } $ fpdi = new FPDI ; // merger operations /* @var $file PdfObject */ foreach ( $ this -> _files as $ file ) { $ filename = $ file -> path ; $ filepages = $ file -> pages ; $ count = $ fpdi -> setSourceFile ( $ filename ) ; //add the pages if ( $ filepages == 'all' ) { for ( $ i = 1 ; $ i <= $ count ; $ i ++ ) { $ template = $ fpdi -> importPage ( $ i ) ; $ size = $ fpdi -> getTemplateSize ( $ template ) ; $ fpdi -> AddPage ( $ file -> getOrientationCode ( ) , array ( $ size [ 'width' ] , $ size [ 'height' ] ) ) ; $ fpdi -> useTemplate ( $ template ) ; } } else { foreach ( $ filepages as $ page ) { if ( ! $ template = $ fpdi -> importPage ( $ page ) ) { throw new Exception ( "Could not load page '$page' in PDF '$filename'. Check that the page exists." ) ; } $ size = $ fpdi -> getTemplateSize ( $ template ) ; $ fpdi -> AddPage ( $ file -> getOrientationCode ( ) , array ( $ size [ 'w' ] , $ size [ 'h' ] ) ) ; $ fpdi -> useTemplate ( $ template ) ; } } } //output operations $ mode = $ this -> _switchmode ( $ outputmode ) ; if ( $ mode == 'S' ) { return $ fpdi -> Output ( $ outputpath , 'S' ) ; } else { if ( $ fpdi -> Output ( $ outputpath , $ mode ) == '' ) { return true ; } else { throw new Exception ( "Error outputting PDF to '$outputmode'." ) ; return false ; } } }
Merge it.
@param $outputmode
@param $outputname
@return PDF
Merge it .