Skip to content

Commit 23693b4

Browse files
committed
change impl to avoid compilation issue
1 parent 2d87fd3 commit 23693b4

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/PhpWord/Writer/PDF/MPDF.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
*/
3030
class MPDF extends AbstractRenderer implements WriterInterface
3131
{
32+
/**
33+
* Overridden to set the correct includefile, only needed for MPDF 5
34+
*
35+
* @codeCoverageIgnore
36+
* @param PhpWord $phpWord
37+
*/
3238
public function __construct(PhpWord $phpWord)
3339
{
3440
if (file_exists(Settings::getPdfRendererPath() . '/mpdf.php')) {
@@ -52,13 +58,8 @@ public function save($filename = null)
5258
$orientation = strtoupper('portrait');
5359

5460
// Create PDF
55-
if ($this->includeFile != null) {
56-
// MPDF version 5.*
57-
$pdf = new \mpdf();
58-
} else {
59-
// MPDF version > 6.*
60-
$pdf = new \Mpdf\Mpdf();
61-
}
61+
$mPdfClass = $this->getMPdfClassName();
62+
$pdf = new $mPdfClass();
6263
$pdf->_setPageSize($paperSize, $orientation);
6364
$pdf->addPage($orientation);
6465

@@ -78,4 +79,21 @@ public function save($filename = null)
7879

7980
parent::restoreStateAfterSave($fileHandle);
8081
}
82+
83+
/**
84+
* Return classname of MPDF to instantiate
85+
*
86+
* @codeCoverageIgnore
87+
* @return string
88+
*/
89+
private function getMPdfClassName()
90+
{
91+
if ($this->includeFile != null) {
92+
// MPDF version 5.*
93+
return '\mpdf';
94+
}
95+
96+
// MPDF version > 6.*
97+
return '\Mpdf\Mpdf';
98+
}
8199
}

0 commit comments

Comments
 (0)