public function render($viewFile, array $options = [])
    {
        $options = Hash::merge([
            'target' => self::TARGET_RETURN,
            'filename' => 'pdf.pdf',
        ], $options);

        $mpdf = $this->_preparePdf($viewFile, $options['viewVars']);
        $options['viewVars']['mpdf'] = $mpdf;

        if (!is_array($viewFile)) {
            $wholeString = $this->_getView()->element($viewFile, $options['viewVars']);
            // use 10% less than pcre.backtrack_limit to account for multibyte characters
            $splitLength = ini_get('pcre.backtrack_limit') - (ini_get('pcre.backtrack_limit') / 10);
            $splitString = str_split($wholeString, $splitLength);
            foreach ($splitString as $string) {
                $mpdf->WriteHTML($string);
            }
        }

        switch ($options['target']) {
            case self::TARGET_RETURN:
                return $mpdf;
                break;
            case self::TARGET_DOWNLOAD:
                $mpdf->Output($options['filename'], 'D');
                break;
            case self::TARGET_BROWSER:
                $mpdf->Output($options['filename'], 'I');
                break;
            case self::TARGET_FILE:
                $mpdf->Output($options['filename'], 'F');
                break;
            case self::TARGET_BINARY:
                return $mpdf->Output('', 'S');
                break;
            default:
                throw new \InvalidArgumentException("{$options['target']} is not a valid target");
                break;
        }
    }
public function render($viewFile, array $options = [])
    {
        $options = Hash::merge([
            'target' => self::TARGET_RETURN,
            'filename' => 'pdf.pdf',
        ], $options);

        $mpdf = $this->_preparePdf($viewFile, $options['viewVars']);
        $options['viewVars']['mpdf'] = $mpdf;

        if (!is_array($viewFile)) {
            $wholeString = $this->_getView()->element($viewFile, $options['viewVars']);
            // use 10% less than pcre.backtrack_limit to account for multibyte characters
            $splitLength = ini_get('pcre.backtrack_limit') - (ini_get('pcre.backtrack_limit') / 10);
            $splitString = str_split($wholeString, $splitLength);
            foreach ($splitString as $string) {
                $mpdf->WriteHTML($string);
            }
        }

        switch ($options['target']) {
            case self::TARGET_RETURN:
                return $mpdf;
                break;
            case self::TARGET_DOWNLOAD:
                $mpdf->Output($options['filename'], 'D');
                break;
            case self::TARGET_BROWSER:
                $mpdf->Output($options['filename'], 'I');
                break;
            case self::TARGET_FILE:
                $mpdf->Output($options['filename'], 'F');
                break;
            case self::TARGET_BINARY:
                return $mpdf->Output('', 'S');
                break;
            default:
                throw new \InvalidArgumentException("{$options['target']} is not a valid target");
                break;
        }
    }
public function render ( $ viewFile , array $ options = [ ] ) { $ options = Hash :: merge ( [ 'target' => self :: TARGET_RETURN , 'filename' => 'pdf.pdf' , ] , $ options ) ; $ mpdf = $ this -> _preparePdf ( $ viewFile , $ options [ 'viewVars' ] ) ; $ options [ 'viewVars' ] [ 'mpdf' ] = $ mpdf ; if ( ! is_array ( $ viewFile ) ) { $ wholeString = $ this -> _getView ( ) -> element ( $ viewFile , $ options [ 'viewVars' ] ) ; // use 10% less than pcre.backtrack_limit to account for multibyte characters $ splitLength = ini_get ( 'pcre.backtrack_limit' ) - ( ini_get ( 'pcre.backtrack_limit' ) / 10 ) ; $ splitString = str_split ( $ wholeString , $ splitLength ) ; foreach ( $ splitString as $ string ) { $ mpdf -> WriteHTML ( $ string ) ; } } switch ( $ options [ 'target' ] ) { case self :: TARGET_RETURN : return $ mpdf ; break ; case self :: TARGET_DOWNLOAD : $ mpdf -> Output ( $ options [ 'filename' ] , 'D' ) ; break ; case self :: TARGET_BROWSER : $ mpdf -> Output ( $ options [ 'filename' ] , 'I' ) ; break ; case self :: TARGET_FILE : $ mpdf -> Output ( $ options [ 'filename' ] , 'F' ) ; break ; case self :: TARGET_BINARY : return $ mpdf -> Output ( '' , 'S' ) ; break ; default : throw new \ InvalidArgumentException ( "{$options['target']} is not a valid target" ) ; break ; } }
Render a view file

@param string|array  $viewFile Path to the View file to render or array with multiple
@param array $options Options
- target
- TARGET_RETURN: Return the MPDF instance
- TARGET_BROWSER: Send the rendered PDF file to the browser
- TARGET_FILE: Save the PDF to the given file
- viewVars: Variables to pass to the $viewFile
- filename: Used with TARGET_BROWSER and TARGET_FILE
@return mixed
Render a view file