protected function _preparePdf($viewFile, $viewVars): Mpdf
    {
        $mpdf = new Mpdf($this->_config['mpdfSettings']);

        if (is_callable($this->_config['mpdfConfigurationCallback'])) {
            $this->_config['mpdfConfigurationCallback']($mpdf);
        }

        $styles = '';
        if ($this->_config['cssFile']) {
            $styles = file_get_contents($this->_config['cssFile']);
        }
        if ($this->_config['cssStyles']) {
            $styles .= $this->_config['cssStyles'];
        }
        if (!empty($styles)) {
            $mpdf->WriteHTML($styles, 1);
        }

        if ($this->_config['pdfSourceFile']) {
            $mpdf->SetImportUse();
            $pagecount = $mpdf->SetSourceFile($this->_config['pdfSourceFile']);
            if ($pagecount > 1) {
                for ($i = 0; $i <= $pagecount; ++$i) {
                    // Import next page from the pdfSourceFile
                    $pageNumber = $i + 1;
                    if ($pageNumber <= $pagecount) {
                        $importPage = $mpdf->ImportPage($pageNumber);
                        $mpdf->UseTemplate($importPage);
                        if (is_array($viewFile) && isset($viewFile[$i])) {
                            $mpdf->WriteHTML($this->_getView()->element($viewFile[$i], $viewVars));
                        }
                    }

                    if ($pageNumber < $pagecount) {
                        $mpdf->AddPage();
                    }
                }
            } else {
                $tplId = $mpdf->ImportPage($pagecount);
                $mpdf->SetPageTemplate($tplId);
            }
        }

        return $mpdf;
    }
protected function _preparePdf($viewFile, $viewVars): Mpdf
    {
        $mpdf = new Mpdf($this->_config['mpdfSettings']);

        if (is_callable($this->_config['mpdfConfigurationCallback'])) {
            $this->_config['mpdfConfigurationCallback']($mpdf);
        }

        $styles = '';
        if ($this->_config['cssFile']) {
            $styles = file_get_contents($this->_config['cssFile']);
        }
        if ($this->_config['cssStyles']) {
            $styles .= $this->_config['cssStyles'];
        }
        if (!empty($styles)) {
            $mpdf->WriteHTML($styles, 1);
        }

        if ($this->_config['pdfSourceFile']) {
            $mpdf->SetImportUse();
            $pagecount = $mpdf->SetSourceFile($this->_config['pdfSourceFile']);
            if ($pagecount > 1) {
                for ($i = 0; $i <= $pagecount; ++$i) {
                    // Import next page from the pdfSourceFile
                    $pageNumber = $i + 1;
                    if ($pageNumber <= $pagecount) {
                        $importPage = $mpdf->ImportPage($pageNumber);
                        $mpdf->UseTemplate($importPage);
                        if (is_array($viewFile) && isset($viewFile[$i])) {
                            $mpdf->WriteHTML($this->_getView()->element($viewFile[$i], $viewVars));
                        }
                    }

                    if ($pageNumber < $pagecount) {
                        $mpdf->AddPage();
                    }
                }
            } else {
                $tplId = $mpdf->ImportPage($pagecount);
                $mpdf->SetPageTemplate($tplId);
            }
        }

        return $mpdf;
    }
protected function _preparePdf ( $ viewFile , $ viewVars ) : Mpdf { $ mpdf = new Mpdf ( $ this -> _config [ 'mpdfSettings' ] ) ; if ( is_callable ( $ this -> _config [ 'mpdfConfigurationCallback' ] ) ) { $ this -> _config [ 'mpdfConfigurationCallback' ] ( $ mpdf ) ; } $ styles = '' ; if ( $ this -> _config [ 'cssFile' ] ) { $ styles = file_get_contents ( $ this -> _config [ 'cssFile' ] ) ; } if ( $ this -> _config [ 'cssStyles' ] ) { $ styles .= $ this -> _config [ 'cssStyles' ] ; } if ( ! empty ( $ styles ) ) { $ mpdf -> WriteHTML ( $ styles , 1 ) ; } if ( $ this -> _config [ 'pdfSourceFile' ] ) { $ mpdf -> SetImportUse ( ) ; $ pagecount = $ mpdf -> SetSourceFile ( $ this -> _config [ 'pdfSourceFile' ] ) ; if ( $ pagecount > 1 ) { for ( $ i = 0 ; $ i <= $ pagecount ; ++ $ i ) { // Import next page from the pdfSourceFile $ pageNumber = $ i + 1 ; if ( $ pageNumber <= $ pagecount ) { $ importPage = $ mpdf -> ImportPage ( $ pageNumber ) ; $ mpdf -> UseTemplate ( $ importPage ) ; if ( is_array ( $ viewFile ) && isset ( $ viewFile [ $ i ] ) ) { $ mpdf -> WriteHTML ( $ this -> _getView ( ) -> element ( $ viewFile [ $ i ] , $ viewVars ) ) ; } } if ( $ pageNumber < $ pagecount ) { $ mpdf -> AddPage ( ) ; } } } else { $ tplId = $ mpdf -> ImportPage ( $ pagecount ) ; $ mpdf -> SetPageTemplate ( $ tplId ) ; } } return $ mpdf ; }
Instanciate and configure the MPDF instance

@param string|array $viewFile    One or more view files
@param array        $viewVars    View variables
@return \Mpdf\Mpdf
Instanciate and configure the MPDF instance