Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to use customized pdf library #1983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function __call($function, $args)
} else {
// All other elements
array_unshift($args, $element); // Prepend element name to the beginning of args array

return call_user_func_array(array($this, 'addElement'), $args);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/PhpWord/Writer/PDF/DomPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ class DomPDF extends AbstractRenderer implements WriterInterface
*/
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.
*
Expand All @@ -49,7 +59,7 @@ public function save($filename = null)
$orientation = 'portrait';

// Create PDF
$pdf = new DompdfLib();
$pdf = $this->createExternalWriterInstance();
$pdf->setPaper(strtolower($paperSize), $orientation);
$pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent()));
$pdf->render();
Expand Down
15 changes: 13 additions & 2 deletions src/PhpWord/Writer/PDF/MPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public function __construct(PhpWord $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.
*
Expand All @@ -58,8 +70,7 @@ public function save($filename = null)
$orientation = strtoupper('portrait');

// Create PDF
$mPdfClass = $this->getMPdfClassName();
$pdf = new $mPdfClass();
$pdf = $this->createExternalWriterInstance();
$pdf->_setPageSize($paperSize, $orientation);
$pdf->addPage($orientation);

Expand Down
16 changes: 15 additions & 1 deletion src/PhpWord/Writer/PDF/TCPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ class TCPDF extends AbstractRenderer implements WriterInterface
*/
protected $includeFile = 'tcpdf.php';

/**
* 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.
*
Expand All @@ -50,7 +64,7 @@ public function save($filename = null)
$orientation = 'P';

// Create PDF
$pdf = new \TCPDF($orientation, 'pt', $paperSize);
$pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize);
$pdf->setFontSubsetting(false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
Expand Down