src/LynX39/LaraPdfMerger/PdfManage.php
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf', $orientation = null, $meta = [])
    {
        if (!isset($this->_files) || !is_array($this->_files)) {
            throw new Exception("No PDFs to merge.");
        }

        $fpdi = new TCPDI;
        $fpdi->setPrintHeader(false);
        $fpdi->setPrintFooter(false);
        
        // setting the meta tags
        if (!empty($meta)) {
            $this->setMeta($meta);
        }

        // merger operations
        foreach ($this->_files as $file) {
            $filename  = $file[0];
            $filepages = $file[1];
            $fileorientation = (!is_null($file[2])) ? $file[2] : $orientation;

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

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

                    if($orientation==null)$fileorientation=$size['w']< $size['h']?'P' : 'L';
                    
                    $fpdi->AddPage($fileorientation, array($size['w'], $size['h']));
                    $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);

                    if($orientation==null)$fileorientation=$size['w']< $size['h']?'P' : 'L';
                    
                    $fpdi->AddPage($fileorientation, 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', $orientation = null, $meta = [])
    {
        if (!isset($this->_files) || !is_array($this->_files)) {
            throw new Exception("No PDFs to merge.");
        }

        $fpdi = new TCPDI;
        $fpdi->setPrintHeader(false);
        $fpdi->setPrintFooter(false);
        
        // setting the meta tags
        if (!empty($meta)) {
            $this->setMeta($meta);
        }

        // merger operations
        foreach ($this->_files as $file) {
            $filename  = $file[0];
            $filepages = $file[1];
            $fileorientation = (!is_null($file[2])) ? $file[2] : $orientation;

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

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

                    if($orientation==null)$fileorientation=$size['w']< $size['h']?'P' : 'L';
                    
                    $fpdi->AddPage($fileorientation, array($size['w'], $size['h']));
                    $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);

                    if($orientation==null)$fileorientation=$size['w']< $size['h']?'P' : 'L';
                    
                    $fpdi->AddPage($fileorientation, 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' , $ orientation = null , $ meta = [ ] ) { if ( ! isset ( $ this -> _files ) || ! is_array ( $ this -> _files ) ) { throw new Exception ( "No PDFs to merge." ) ; } $ fpdi = new TCPDI ; $ fpdi -> setPrintHeader ( false ) ; $ fpdi -> setPrintFooter ( false ) ; // setting the meta tags if ( ! empty ( $ meta ) ) { $ this -> setMeta ( $ meta ) ; } // merger operations foreach ( $ this -> _files as $ file ) { $ filename = $ file [ 0 ] ; $ filepages = $ file [ 1 ] ; $ fileorientation = ( ! is_null ( $ file [ 2 ] ) ) ? $ file [ 2 ] : $ orientation ; $ count = $ fpdi -> setSourceFile ( $ filename ) ; //add the pages if ( $ filepages == 'all' ) { for ( $ i = 1 ; $ i <= $ count ; $ i ++ ) { $ template = $ fpdi -> importPage ( $ i ) ; $ size = $ fpdi -> getTemplateSize ( $ template ) ; if ( $ orientation == null ) $ fileorientation = $ size [ 'w' ] < $ size [ 'h' ] ? 'P' : 'L' ; $ fpdi -> AddPage ( $ fileorientation , array ( $ size [ 'w' ] , $ size [ 'h' ] ) ) ; $ 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 ) ; if ( $ orientation == null ) $ fileorientation = $ size [ 'w' ] < $ size [ 'h' ] ? 'P' : 'L' ; $ fpdi -> AddPage ( $ fileorientation , 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 ; } } }
Merges your provided PDFs and outputs to specified location.
@param $outputmode
@param $outputname
@param $orientation
@array $meta [title => $title, author => $author, subject => $subject, keywords => $keywords, creator => $creator]
@return PDF
Merges your provided PDFs and outputs to specified location .