protected function renderPdf($html, $filename, $options) { $this->_helper->viewRenderer->setNoRender(); $margin_left = isset($options['margins']['left']) ? $options['margins']['left'] : 15; $margin_right = isset($options['margins']['right']) ? $options['margins']['right'] : 15; $margin_top = isset($options['margins']['top']) ? $options['margins']['top'] : 15; $margin_bottom = isset($options['margins']['bottom']) ? $options['margins']['bottom'] : 15; $margin_header = isset($options['margins']['header']) ? $options['margins']['header'] : 15; $margin_footer = isset($options['margins']['footer']) ? $options['margins']['footer'] : 15; $format = isset($options['format']) ? $options['format'] : 'A4-L'; $output_mode = isset($options['output']) ? $options['output'] : 'D'; define('_MPDF_URI', APPLICATION_PATH . '/../library/MPDF54/'); define('_MPDF_TEMP_PATH', '/var/www/tm/'); require_once APPLICATION_PATH . "/../library/MPDF54/mpdf.php"; /* argumentos: * mode: codificacao (basicamente) * format: formato da pagina (pode ser adicionado -L depois do formato para forcar modo paisagem * tamanho da fonte: e passado 0 para que o tamanho seja setado no arquivo CSS * fonte * margin_left * margin_right * margin_top * margin_bottom * margin_header * margin_footer */ $mpdf = new mPDF('utf-8', $format, 0, '', $margin_left, $margin_right, $margin_top, $margin_bottom, $margin_header, $margin_footer); $mpdf->ignore_invalid_utf8 = true; $mpdf->charset_in = 'utf-8'; $mpdf->SetDisplayMode('fullpage', 'two'); $mpdf->WriteHTML($mpdf->purify_utf8($html)); $mpdf->Output($filename . '.pdf', $output_mode); exit; }
/** * Gerar PDF * * @param string $sHtml * @param string $sFilename * @param array $aOptions * @return string */ public static function renderPdf($sHtml, $sFilename, $aOptions) { $aOptions['margins']['left'] = isset($aOptions['margins']['left']) ? $aOptions['margins']['left'] : 5; $aOptions['margins']['right'] = isset($aOptions['margins']['right']) ? $aOptions['margins']['right'] : 5; $aOptions['margins']['top'] = isset($aOptions['margins']['top']) ? $aOptions['margins']['top'] : 5; $aOptions['margins']['bottom'] = isset($aOptions['margins']['bottom']) ? $aOptions['margins']['bottom'] : 5; $aOptions['margins']['header'] = isset($aOptions['margins']['header']) ? $aOptions['margins']['header'] : 5; $aOptions['margins']['footer'] = isset($aOptions['margins']['footer']) ? $aOptions['margins']['footer'] : 5; $aOptions['format'] = isset($aOptions['format']) ? $aOptions['format'] : 'A4-L'; $aOptions['output'] = isset($aOptions['output']) ? $aOptions['output'] : 'D'; /** * Argumentos: * ------------------------------------------------------------------------------------------------ * charset: (utf-8) * format: formato da pagina (pode ser adicionado -L depois do formato para forcar modo paisagem * tamanho da fonte: e passado 0 para que o tamanho seja setado no arquivo CSS * fonte * margin_left * margin_right * margin_top * margin_bottom * margin_header * margin_footer */ $oMpdf = new mPDF('utf-8', $aOptions['format'], 0, '', $aOptions['margins']['left'], $aOptions['margins']['right'], $aOptions['margins']['top'], $aOptions['margins']['bottom'], $aOptions['margins']['header'], $aOptions['margins']['footer']); $oMpdf->ignore_invalid_utf8 = true; $oMpdf->charset_in = 'utf-8'; $oMpdf->SetDisplayMode('fullpage', 'two'); $oMpdf->WriteHTML($oMpdf->purify_utf8($sHtml)); $oMpdf->Output($sFilename . '.pdf', $aOptions['output']); return $sFilename; }
/** * Gerar PDF através do HTML informado * * @param string $sHtml * @param string $sFilename * @param array $aOptions * $aOptions['margins']['left'] = 15; * $aOptions['margins']['right'] = 15; * $aOptions['margins']['top'] = 15; * $aOptions['margins']['bottom'] = 15; * $aOptions['margins']['header'] = 15; * $aOptions['margins']['footer'] = 15; * $aOptions['format'] = 'A4-L'; * $aOptions['output'] = 'D'; // 'D' = Download | 'F' = Salva o arquivo */ protected function renderPdf($sHtml, $sFilename, $aOptions) { self::noLayout(); $aOptions['margins']['left'] = isset($aOptions['margins']['left']) ? $aOptions['margins']['left'] : 15; $aOptions['margins']['right'] = isset($aOptions['margins']['right']) ? $aOptions['margins']['right'] : 15; $aOptions['margins']['top'] = isset($aOptions['margins']['top']) ? $aOptions['margins']['top'] : 15; $aOptions['margins']['bottom'] = isset($aOptions['margins']['bottom']) ? $aOptions['margins']['bottom'] : 15; $aOptions['margins']['header'] = isset($aOptions['margins']['header']) ? $aOptions['margins']['header'] : 15; $aOptions['margins']['footer'] = isset($aOptions['margins']['footer']) ? $aOptions['margins']['footer'] : 15; $aOptions['format'] = isset($aOptions['format']) ? $aOptions['format'] : 'A4-L'; $aOptions['output'] = isset($aOptions['output']) ? $aOptions['output'] : 'D'; define('_MPDF_URI', LIBRARY_PATH . '/MPDF54/'); define('_MPDF_TEMP_PATH', TEMP_PATH . '/'); require_once LIBRARY_PATH . '/MPDF54/mpdf.php'; $oMpdf = new mPDF('utf-8', $aOptions['format'], 0, '', $aOptions['margins']['left'], $aOptions['margins']['right'], $aOptions['margins']['top'], $aOptions['margins']['bottom'], $aOptions['margins']['header'], $aOptions['margins']['footer']); $oMpdf->ignore_invalid_utf8 = TRUE; $oMpdf->charset_in = 'utf-8'; $oMpdf->SetDisplayMode('fullpage', 'two'); $oMpdf->WriteHTML($oMpdf->purify_utf8($sHtml)); $oMpdf->Output("{$sFilename}.pdf", $aOptions['output']); exit; }