Beispiel #1
1
 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());
 }
Beispiel #2
0
 protected function _convertAndPost($sChatId, $sHTML)
 {
     $sTempFile = tempnam(sys_get_temp_dir(), 'webpage');
     $oOptions = new Options();
     $oOptions->setPdfBackend('GD');
     $oOptions->setFontDir(realpath(__DIR__ . '/../fonts'));
     $oOptions->setIsRemoteEnabled(true);
     $dompdf = new DOMPDF($oOptions);
     $dompdf->load_html($sHTML, 'UTF-8');
     $dompdf->render();
     file_put_contents($sTempFile . '.png', $dompdf->output(array('compress' => 0)));
     $aRes = $this->sendPhoto($sChatId, $sTempFile . '.png');
     unlink($sTempFile . '.png');
     return $aRes;
 }
Beispiel #3
0
 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()));
 }
Beispiel #4
0
 /**
  * @param array $style
  * @param string $remoteFile
  * @param resource $context
  * @return bool
  */
 public function registerFont($style, $remoteFile, $context = null)
 {
     $fontDir = $this->getOptions()->getFontDir();
     $fontname = mb_strtolower($style["family"]);
     $families = $this->getFontFamilies();
     $entry = array();
     if (isset($families[$fontname])) {
         $entry = $families[$fontname];
     }
     $localFile = $fontDir . DIRECTORY_SEPARATOR . md5($remoteFile);
     $localTempFile = $this->options->get('tempDir') . "/" . md5($remoteFile);
     $cacheEntry = $localFile;
     $localFile .= "." . strtolower(pathinfo($remoteFile, PATHINFO_EXTENSION));
     $styleString = $this->getType("{$style['weight']} {$style['style']}");
     if (!isset($entry[$styleString])) {
         $entry[$styleString] = $cacheEntry;
         // Download the remote file
         $remoteFileContent = @Helpers::getFileContent($remoteFile, null, $context);
         if (false === $remoteFileContent) {
             return false;
         }
         file_put_contents($localTempFile, $remoteFileContent);
         $font = Font::load($localTempFile);
         if (!$font) {
             unlink($localTempFile);
             return false;
         }
         $font->parse();
         $font->saveAdobeFontMetrics("{$cacheEntry}.ufm");
         $font->close();
         if (file_exists($localTempFile)) {
             unlink($localTempFile);
         }
         if (!file_exists("{$cacheEntry}.ufm")) {
             return false;
         }
         // Save the changes
         file_put_contents($localFile, $remoteFileContent);
         if (!file_exists($localFile)) {
             unlink("{$cacheEntry}.ufm");
             return false;
         }
         $this->setFontFamily($fontname, $entry);
         $this->saveFontFamilies();
     }
     return true;
 }
Beispiel #5
0
 /**
  * @param array $options
  * @return $this
  * @deprecated
  */
 public function set_options(array $options)
 {
     $this->options->set($options);
     return $this;
 }
Beispiel #6
0
 /**
  * @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);
     }
 }
Beispiel #7
0
 /**
  * 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;
 }
Beispiel #8
-1
 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());
 }
Beispiel #9
-1
 /**
  * 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();
 }
Beispiel #10
-2
 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);
 }