public function DomPdf::send in Entity Print 8
Send the PDF contents to the browser.
Parameters
$filename: (optional) The filename if we want to force the browser to download.
Throws
\Drupal\entity_print\PdfEngineException Thrown when PDF generation fails.
Overrides PdfEngineInterface::send
File
- src/
Plugin/ EntityPrint/ PdfEngine/ DomPdf.php, line 124
Class
- DomPdf
- @PdfEngine( id = "dompdf", label = @Translation("Dompdf") )
Namespace
Drupal\entity_print\Plugin\EntityPrint\PdfEngineCode
public function send($filename = NULL) {
$this->pdf
->render();
// Dompdf doesn't have a return value for send so just check the error
// global it provides.
if ($errors = $this
->getError()) {
throw new PdfEngineException(sprintf('Failed to generate PDF: %s', $errors));
}
// The Dompdf library internally adds the .pdf extension so we remove it
// from our filename here.
$filename = preg_replace('/\\.pdf$/i', '', $filename);
// If the filename received here is NULL, force open in the browser
// otherwise attempt to have it downloaded.
$this->pdf
->stream($filename, array(
'Attachment' => (bool) $filename,
));
}