Merge pull request #1983 from FCG-Group/allow_to_use_customized_pdf_libraries

allow to use customized pdf library
This commit is contained in:
troosan 2020-12-29 23:41:23 +01:00 committed by GitHub
commit 7c7d7fd405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 3 deletions

View File

@ -35,6 +35,16 @@ class DomPDF extends AbstractRenderer implements WriterInterface
*/ */
protected $includeFile = null; protected $includeFile = null;
/**
* Gets the implementation of external PDF library that should be used.
*
* @return Dompdf implementation
*/
protected function createExternalWriterInstance()
{
return new DompdfLib();
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
* *
@ -49,7 +59,7 @@ class DomPDF extends AbstractRenderer implements WriterInterface
$orientation = 'portrait'; $orientation = 'portrait';
// Create PDF // Create PDF
$pdf = new DompdfLib(); $pdf = $this->createExternalWriterInstance();
$pdf->setPaper(strtolower($paperSize), $orientation); $pdf->setPaper(strtolower($paperSize), $orientation);
$pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent())); $pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent()));
$pdf->render(); $pdf->render();

View File

@ -44,6 +44,18 @@ class MPDF extends AbstractRenderer implements WriterInterface
parent::__construct($phpWord); parent::__construct($phpWord);
} }
/**
* Gets the implementation of external PDF library that should be used.
*
* @return Mpdf implementation
*/
protected function createExternalWriterInstance()
{
$mPdfClass = $this->getMPdfClassName();
return new $mPdfClass();
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
* *
@ -58,8 +70,7 @@ class MPDF extends AbstractRenderer implements WriterInterface
$orientation = strtoupper('portrait'); $orientation = strtoupper('portrait');
// Create PDF // Create PDF
$mPdfClass = $this->getMPdfClassName(); $pdf = $this->createExternalWriterInstance();
$pdf = new $mPdfClass();
$pdf->_setPageSize($paperSize, $orientation); $pdf->_setPageSize($paperSize, $orientation);
$pdf->addPage($orientation); $pdf->addPage($orientation);

View File

@ -50,6 +50,20 @@ class TCPDF extends AbstractRenderer implements WriterInterface
return new \TCPDF($orientation, $unit, $paperSize); return new \TCPDF($orientation, $unit, $paperSize);
} }
/**
* Gets the implementation of external PDF library that should be used.
*
* @param string $orientation Page orientation
* @param string $unit Unit measure
* @param string $paperSize Paper size
*
* @return \TCPDF implementation
*/
protected function createExternalWriterInstance($orientation, $unit, $paperSize)
{
return new \TCPDF($orientation, $unit, $paperSize);
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
* *