public function EntityPrintPdfBuilder::getEntityRenderedAsPdf in Entity Print 8
Render any content entity as a PDF.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The content entity to render.
\Drupal\entity_print\Plugin\PdfEngineInterface $pdf_engine: The plugin id of the PDF engine to use.
bool $force_download: (optional) TRUE to try and force the PDF to be downloaded rather than opened.
bool $use_default_css: (optional) TRUE if you want the default CSS included, otherwise FALSE.
Return value
string FALSE or the PDF content will be sent to the browser.
Overrides PdfBuilderInterface::getEntityRenderedAsPdf
File
- src/
EntityPrintPdfBuilder.php, line 45
Class
Namespace
Drupal\entity_printCode
public function getEntityRenderedAsPdf(EntityInterface $entity, PdfEngineInterface $pdf_engine, $force_download = FALSE, $use_default_css = TRUE) {
$pdf_engine
->addPage($this->rendererFactory
->create($entity)
->getHtml($entity, $use_default_css, TRUE));
// Allow other modules to alter the generated PDF object.
$this->dispatcher
->dispatch(PdfEvents::PRE_SEND, new PreSendPdfEvent($pdf_engine, $entity));
// If we're forcing a download we need a filename otherwise it's just sent
// straight to the browser.
$filename = $force_download ? $this
->generateFilename($entity) : NULL;
return $pdf_engine
->send($filename);
}