diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 8de1a8df80..ccae8d4919 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -99,6 +99,13 @@ class Settings */ private static $pdfRendererPath = null; + /** + * Config to the external Library used for rendering PDF files + * + * @var string + */ + private static $pdfRendererConfig = null; + /** * Measurement unit * @@ -230,6 +237,19 @@ public static function setPdfRendererName($libraryName) return true; } + /** + * Set the config to use for the PDF Rendering Library. + * + * @param array $libraryConfig + * @return string + */ + public static function setPdfRendererConfig($libraryConfig) + { + self::$pdfRendererConfig = $libraryConfig; + + return true; + } + /** * Return the directory path to the PDF Rendering Library. * @@ -240,6 +260,16 @@ public static function getPdfRendererPath() return self::$pdfRendererPath; } + /** + * Return the config to instantiate PDF Rendering Library. + * + * @return array + */ + public static function getPdfRendererConfig() + { + return self::$pdfRendererConfig; + } + /** * Location of external library to use for rendering PDF files * diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index e63f5dfd68..3a2c9c836b 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -29,6 +29,9 @@ */ class MPDF extends AbstractRenderer implements WriterInterface { + const MPDF_5 = '\mpdf'; + const MPDF_6 = '\Mpdf\Mpdf'; + /** * Overridden to set the correct includefile, only needed for MPDF 5 * @@ -59,7 +62,12 @@ public function save($filename = null) // Create PDF $mPdfClass = $this->getMPdfClassName(); - $pdf = new $mPdfClass(); + if (self::MPDF_5 === $mPdfClass) { + $pdf = new $mPdfClass(); + } else { + $mPdfConfig = Settings::getPdfRendererConfig() ?: array(); + $pdf = new $mPdfClass($mPdfConfig); + } $pdf->_setPageSize($paperSize, $orientation); $pdf->addPage($orientation); @@ -90,10 +98,10 @@ private function getMPdfClassName() { if ($this->includeFile != null) { // MPDF version 5.* - return '\mpdf'; + return self::MPDF_5; } // MPDF version > 6.* - return '\Mpdf\Mpdf'; + return self::MPDF_6; } }