Skip to content

Commit 7c7d7fd

Browse files
authored
Merge pull request #1983 from FCG-Group/allow_to_use_customized_pdf_libraries
allow to use customized pdf library
2 parents 31d8b54 + c8de86a commit 7c7d7fd

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/PhpWord/Writer/PDF/DomPDF.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ class DomPDF extends AbstractRenderer implements WriterInterface
3535
*/
3636
protected $includeFile = null;
3737

38+
/**
39+
* Gets the implementation of external PDF library that should be used.
40+
*
41+
* @return Dompdf implementation
42+
*/
43+
protected function createExternalWriterInstance()
44+
{
45+
return new DompdfLib();
46+
}
47+
3848
/**
3949
* Save PhpWord to file.
4050
*
@@ -49,7 +59,7 @@ public function save($filename = null)
4959
$orientation = 'portrait';
5060

5161
// Create PDF
52-
$pdf = new DompdfLib();
62+
$pdf = $this->createExternalWriterInstance();
5363
$pdf->setPaper(strtolower($paperSize), $orientation);
5464
$pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent()));
5565
$pdf->render();

src/PhpWord/Writer/PDF/MPDF.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public function __construct(PhpWord $phpWord)
4444
parent::__construct($phpWord);
4545
}
4646

47+
/**
48+
* Gets the implementation of external PDF library that should be used.
49+
*
50+
* @return Mpdf implementation
51+
*/
52+
protected function createExternalWriterInstance()
53+
{
54+
$mPdfClass = $this->getMPdfClassName();
55+
56+
return new $mPdfClass();
57+
}
58+
4759
/**
4860
* Save PhpWord to file.
4961
*
@@ -58,8 +70,7 @@ public function save($filename = null)
5870
$orientation = strtoupper('portrait');
5971

6072
// Create PDF
61-
$mPdfClass = $this->getMPdfClassName();
62-
$pdf = new $mPdfClass();
73+
$pdf = $this->createExternalWriterInstance();
6374
$pdf->_setPageSize($paperSize, $orientation);
6475
$pdf->addPage($orientation);
6576

src/PhpWord/Writer/PDF/TCPDF.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ protected function createExternalWriterInstance($orientation, $unit, $paperSize)
5050
return new \TCPDF($orientation, $unit, $paperSize);
5151
}
5252

53+
/**
54+
* Gets the implementation of external PDF library that should be used.
55+
*
56+
* @param string $orientation Page orientation
57+
* @param string $unit Unit measure
58+
* @param string $paperSize Paper size
59+
*
60+
* @return \TCPDF implementation
61+
*/
62+
protected function createExternalWriterInstance($orientation, $unit, $paperSize)
63+
{
64+
return new \TCPDF($orientation, $unit, $paperSize);
65+
}
66+
5367
/**
5468
* Save PhpWord to file.
5569
*

0 commit comments

Comments
 (0)