From efa2a84a760c424eb658387874591032f3693cca Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Sun, 18 Jun 2017 16:56:53 +0530 Subject: [PATCH] Enable mPdf config to be set via `options` reverts #58 --- CHANGE.md | 1 - Pdf.php | 56 +++++++++++++++++-------------------------------------- 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/CHANGE.md b/CHANGE.md index 2f2a70c..83a0bc8 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -5,7 +5,6 @@ Change Log: `yii2-mpdf` **Date:** 17-Jun-2017 -- (enh #58): New property `initConfig` to initialize other Mpdf initial configuration properties. - (enh #45, #51): Updates dependency to use latest mPdf 7.x development branch. ## Version 1.0.1 diff --git a/Pdf.php b/Pdf.php index bea0e88..b8c7c33 100644 --- a/Pdf.php +++ b/Pdf.php @@ -142,10 +142,6 @@ class Pdf extends Component * @var string specifies the default page orientation of the new document. */ public $orientation = self::ORIENT_PORTRAIT; - /** - * @var array additional Mpdf initialization configuration properties. See [[Mpdf]] documentation. - */ - public $initConfig = []; /** * @var string css file to prepend to the PDF */ @@ -179,7 +175,7 @@ class Pdf extends Component */ public $methods = ''; /** - * @var string the Mpdf configuration options entered as `$key => value` pairs, where: + * @var array the Mpdf configuration options entered as `$key => value` pairs, where: * - `$key`: _string_, is the configuration property name * - `$value`: _mixed_, is the configured property value */ @@ -255,7 +251,6 @@ public function initTempPaths() */ public function render() { - $this->configure($this->options); if (!empty($this->methods)) { foreach ($this->methods as $method => $param) { $this->execute($method, $param); @@ -282,19 +277,22 @@ public function getApi() */ public function setApi() { - $config = array_replace_recursive($this->initConfig, [ - 'mode' => $this->mode, - 'format' => $this->format, - 'default_font_size' => $this->defaultFontSize, - 'default_font' => $this->defaultFont, - 'mgl' => $this->marginLeft, - 'mgr' => $this->marginRight, - 'mgt' => $this->marginTop, - 'mgb' => $this->marginBottom, - 'mgh' => $this->marginHeader, - 'mgf' => $this->marginFooter, - 'orientation' => $this->orientation - ]); + $config = array_replace_recursive( + $this->options, + [ + 'mode' => $this->mode, + 'format' => $this->format, + 'default_font_size' => $this->defaultFontSize, + 'default_font' => $this->defaultFont, + 'mgl' => $this->marginLeft, + 'mgr' => $this->marginRight, + 'mgt' => $this->marginTop, + 'mgb' => $this->marginBottom, + 'mgh' => $this->marginHeader, + 'mgf' => $this->marginFooter, + 'orientation' => $this->orientation, + ] + ); if (isset($this->tempPath) && is_dir($this->tempPath)) { $config['tempDir'] = $this->tempPath; } @@ -341,26 +339,6 @@ public function addPdfAttachment($filePath) $this->_pdfAttachments[] = $filePath; } - /** - * Configures Mpdf options - * - * @param array $options the Mpdf configuration options entered as `$key => value` pairs, where: - * - `$key`: _string_, is the configuration property name - * - `$value`: _mixed_, is the configured property value - */ - public function configure($options = []) - { - if (empty($options)) { - return; - } - $api = $this->getApi(); - foreach ($options as $key => $value) { - if (property_exists($api, $key)) { - $api->$key = $value; - } - } - } - /** * Calls the Mpdf method with parameters *