diff --git a/src/Plugin/EntityPrint/PrintEngine/DomPdf.php b/src/Plugin/EntityPrint/PrintEngine/DomPdf.php index 3c4cd14..9c16283 100644 --- a/src/Plugin/EntityPrint/PrintEngine/DomPdf.php +++ b/src/Plugin/EntityPrint/PrintEngine/DomPdf.php @@ -39,6 +39,13 @@ class DomPdf extends PdfEngineBase implements ContainerFactoryPluginInterface { protected $html = ''; /** + * Keep track of whether we've rendered or not. + * + * @var bool + */ + protected $hasRendered; + + /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, ExportTypeInterface $export_type, Request $request) { @@ -143,7 +150,7 @@ class DomPdf extends PdfEngineBase implements ContainerFactoryPluginInterface { * {@inheritdoc} */ public function send($filename, $force_download = TRUE) { - $this->dompdf->render(); + $this->doRender(); // Dompdf doesn't have a return value for send so just check the error // global it provides. @@ -164,12 +171,21 @@ class DomPdf extends PdfEngineBase implements ContainerFactoryPluginInterface { * {@inheritdoc} */ public function getBlob() { - $this->dompdf->render(); - + $this->doRender(); return $this->dompdf->output(); } /** + * Tell Dompdf to render the HTML into a PDF. + */ + protected function doRender() { + if (!$this->hasRendered) { + $this->dompdf->render(); + $this->hasRendered = TRUE; + } + } + + /** * {@inheritdoc} */ protected function getError() { diff --git a/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php b/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php index 8c15c83..e747b6b 100644 --- a/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php +++ b/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php @@ -99,7 +99,7 @@ class PhpWkhtmlToPdf extends PdfEngineBase implements AlignableHeaderFooterInter * {@inheritdoc} */ public function getBlob() { - $this->pdf->toString(); + return $this->pdf->toString(); } /**