public function actionPdf() { $data = $this->getData(); $searchModel = $data['searchModel']; $dataProvider = $data['dataProvider']; $title = $data['title']; $modelName = $data['modelName']; $fields = $this->getFieldsKeys($searchModel->exportFields()); $options = new Options(); $options->set('defaultFont', 'times'); $dompdf = new Dompdf($options); $html = '<html><body>'; $html .= '<h1>' . $title ? $title : $modelName . '</h1>'; $html .= '<table width="100%" cellspacing="0" cellpadding="0">'; $html .= '<tr style="background-color: #ececec;">'; foreach ($fields as $one) { $html .= '<td style="border: 2px solid #cccccc; text-align: center; font-weight: 500;">' . $searchModel->getAttributeLabel($one) . '</td>'; } $html .= '</tr>'; foreach ($dataProvider->getModels() as $model) { $html .= '<tr>'; foreach ($searchModel->exportFields() as $one) { if (is_string($one)) { $html .= '<td style="border: 1px solid #cccccc; text-align: left; font-weight: 300; padding-left: 10px;">' . $model[$one] . '</td>'; } else { $html .= '<td style="border: 1px solid #cccccc; text-align: left; font-weight: 300; padding-left: 10px;">' . $one($model) . '</td>'; } } $html .= '</tr>'; } $html .= '</table>'; $html .= '</body></html>'; $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream($modelName . '_' . time()); }
public function renderControllerAction($controller) { $this->assertNoHeadersSent(); ini_set('memory_limit', '384M'); ini_set('max_execution_time', 300); $viewRenderer = $controller->getHelper('viewRenderer'); $controller->render($viewRenderer->getScriptAction(), $viewRenderer->getResponseSegment(), $viewRenderer->getNoController()); $layout = $controller->getHelper('layout')->setLayout('pdf'); $layout->content = $controller->getResponse(); $html = $layout->render(); $imgDir = Url::fromPath('img'); $html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html); $options = new Options(); $options->set('defaultPaperSize', 'A4'); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->render(); $request = $controller->getRequest(); $dompdf->stream(sprintf('%s-%s-%d', $request->getControllerName(), $request->getActionName(), time())); }
/** * @param array $options * @return $this * @deprecated */ public function set_options(array $options) { $this->options->set($options); return $this; }
/** * @param $paper_size * @param $orientation * @param $html * @param $output * @param string $fileName * * @return string */ public static function _html2pdf_dompdf($paper_size, $orientation, $html, $output, $fileName) { // CRM-12165 - Remote file support required for image handling. $options = new Options(); $options->set('isRemoteEnabled', TRUE); $dompdf = new DOMPDF($options); $dompdf->set_paper($paper_size, $orientation); $dompdf->load_html($html); $dompdf->render(); if ($output) { return $dompdf->output(); } else { // CRM-19183 remove .pdf extension from filename $fileName = basename($fileName, ".pdf"); $dompdf->stream($fileName); } }
/** * Create the Invoice file in upload folder for attachment. * * @param string $html * Content for pdf in html format. * * @param string $name * * @return string * Name of file which is in pdf format */ public static function putFile($html, $name = 'Invoice.pdf') { $options = new Options(); $options->set('isRemoteEnabled', TRUE); $doc = new DOMPDF($options); $doc->load_html($html); $doc->render(); $html = $doc->output(); $config = CRM_Core_Config::singleton(); $fileName = $config->uploadDir . $name; file_put_contents($fileName, $html); return $fileName; }
public function testSetters() { $option = new Options(); $option->set(array('tempDir' => 'test1', 'fontDir' => 'test2', 'fontCache' => 'test3', 'chroot' => 'test4', 'logOutputFile' => 'test5', 'defaultMediaType' => 'test6', 'defaultPaperSize' => 'test7', 'defaultFont' => 'test8', 'dpi' => 300, 'fontHeightRatio' => 1.2, 'isPhpEnabled' => true, 'isRemoteEnabled' => true, 'isJavascriptEnabled' => false, 'isHtml5ParserEnabled' => true, 'isFontSubsettingEnabled' => true, 'debugPng' => true, 'debugKeepTemp' => true, 'debugCss' => true, 'debugLayout' => true, 'debugLayoutLines' => false, 'debugLayoutBlocks' => false, 'debugLayoutInline' => false, 'debugLayoutPaddingBox' => false, 'adminUsername' => 'test9', 'adminPassword' => 'test10')); $this->assertEquals('test1', $option->getTempDir()); $this->assertEquals('test2', $option->getFontDir()); $this->assertEquals('test3', $option->getFontCache()); $this->assertEquals('test4', $option->getChroot()); $this->assertEquals('test5', $option->getLogOutputFile()); $this->assertEquals('test6', $option->getDefaultMediaType()); $this->assertEquals('test7', $option->getDefaultPaperSize()); $this->assertEquals('test8', $option->getDefaultFont()); $this->assertEquals(300, $option->getDpi()); $this->assertEquals(1.2, $option->getFontHeightRatio()); $this->assertTrue($option->getIsPhpEnabled()); $this->assertTrue($option->getIsRemoteEnabled()); $this->assertFalse($option->getIsJavascriptEnabled()); $this->assertTrue($option->getIsHtml5ParserEnabled()); $this->assertTrue($option->getIsFontSubsettingEnabled()); $this->assertTrue($option->getDebugPng()); $this->assertTrue($option->getDebugKeepTemp()); $this->assertTrue($option->getDebugCss()); $this->assertTrue($option->getDebugLayout()); $this->assertFalse($option->getDebugLayoutLines()); $this->assertFalse($option->getDebugLayoutBlocks()); $this->assertFalse($option->getDebugLayoutInline()); $this->assertFalse($option->getDebugLayoutPaddingBox()); $this->assertEquals('test9', $option->getAdminUsername()); $this->assertEquals('test10', $option->getAdminPassword()); }
/** * Capture the invoice as a PDF and return the raw bytes. * * @param array $data * @return string */ public function pdf(array $data = array()) { if (!defined('DOMPDF_ENABLE_AUTOLOAD')) { define('DOMPDF_ENABLE_AUTOLOAD', false); } // if (file_exists($configPath = base_path().'/vendor/dompdf/dompdf/dompdf_config.inc.php')) { // require_once $configPath; // } $options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); $dompdf->loadHtml($this->view($data)->render()); $dompdf->render(); return $dompdf->output(); }
protected function createFromConfig(array $config) { $userConfig = isset($config['dompdf']) ? $config['dompdf'] : []; // evaluate library directory $dompdfDir = isset($userConfig['DOMPDF_DIR']) ? $userConfig['DOMPDF_DIR'] : realpath('vendor/dompdf/dompdf'); // merge default config with user config if necessary $dompdfConfig = count($userConfig) ? array_merge($this->createDefaultSettings($dompdfDir), $userConfig) : $this->createDefaultSettings($dompdfDir); // set options $options = new Options(); foreach ($dompdfConfig as $settingName => $settingValue) { if (!defined($settingName)) { $options->set($settingName, $settingValue); } } return new Dompdf($options); }