diff --git a/CHANGE.md b/CHANGE.md index 983af74..6cb2ced 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -3,8 +3,10 @@ Change Log: `yii2-mpdf` ## Version 1.0.6 -**Date:** _under development_ +**Date:** 14-Apr-2020 +- (enh #106): Fix getCss function. +- (enh #92, #104, #105): Enhancements for MPDF v8.0. - Update README. - (enh #89): Fix README.md & throw InvalidConfigException for invalid CSS config. diff --git a/LICENSE.md b/LICENSE.md index 7f04f80..2deefaa 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2014 - 2018, Kartik Visweswaran +Copyright (c) 2014 - 2020, Kartik Visweswaran Krajee.com All rights reserved. diff --git a/src/Pdf.php b/src/Pdf.php index d48a9e6..203a5e0 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -1,7 +1,7 @@ tempPath)) { $this->tempPath = Yii::getAlias('@runtime/mpdf'); } - $s = DIRECTORY_SEPARATOR; - $prefix = $this->tempPath . $s; - static::definePath('_MPDF_TEMP_PATH', "{$prefix}tmp{$s}"); - static::definePath('_MPDF_TTFONTDATAPATH', "{$prefix}ttfontdata{$s}"); + if (!file_exists($this->tempPath)) { + mkdir($this->tempPath); + } } /** @@ -255,6 +226,10 @@ public function initTempPaths() * * @return mixed * @throws InvalidConfigException + * @throws \Mpdf\MpdfException + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException */ public function render() { @@ -300,26 +275,26 @@ public function setApi() * Fetches the content of the CSS file if supplied * * @return string + * @throws InvalidConfigException */ public function getCss() { if (!empty($this->_css)) { return $this->_css; } - $this->_css = ''; + $this->_css = ''; if (!empty($this->cssFile)) { $cssFiles = is_array($this->cssFile) ? $this->cssFile : [$this->cssFile]; foreach ($cssFiles as $cssFile) { $cssFile = Yii::getAlias($cssFile); if (!empty($cssFile) && file_exists($cssFile)) { $this->_css .= file_get_contents($cssFile); - } - else { + } else { throw new InvalidConfigException("CSS File not found: '{$cssFile}'."); } } } - $this->_css .= $this->cssInline; + $this->_css .= $this->cssInline; return $this->_css; } @@ -374,6 +349,10 @@ public function execute($method, $params = []) * * @return mixed * @throws InvalidConfigException + * @throws \Mpdf\MpdfException + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException */ public function output($content = '', $file = '', $dest = self::DEST_BROWSER) { @@ -392,7 +371,6 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER) $api->WriteHTML($content); } if ($pdfAttachments) { - $api->SetImportUse(); $api->SetHeader(null); $api->SetFooter(null); foreach ($pdfAttachments as $attachment) { @@ -430,7 +408,7 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER) /** * Parse the format automatically based on the orientation */ - protected function parseFormat() + public function parseFormat() { $landscape = self::ORIENT_LANDSCAPE; $tag = '-' . $landscape; @@ -444,9 +422,18 @@ protected function parseFormat() * * @param Mpdf $api the Mpdf API instance * @param string $attachment the attachment name + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException */ - private function writePdfAttachment($api, $attachment) + public function writePdfAttachment($api = null, $attachment = null) { + if ($attachment === null) { + return; + } + if ($api === null) { + $api = $this->getApi(); + } $pageCount = $api->SetSourceFile($attachment); for ($i = 1; $i <= $pageCount; $i++) { $api->AddPage();