public function GeneratePdf::generate in PDF using mPDF 8
Same name and namespace in other branches
- 8.2 src/Controller/GeneratePdf.php \Drupal\pdf_using_mpdf\Controller\GeneratePdf::generate()
Generate a PDF file of a node.
Parameters
\Drupal\node\NodeInterface $node: The node object.
Return value
array Response headers.
Throws
\Exception
1 string reference to 'GeneratePdf::generate'
File
- src/
Controller/ GeneratePdf.php, line 130
Class
- GeneratePdf
- Class GeneratePdf.
Namespace
Drupal\pdf_using_mpdf\ControllerCode
public function generate(NodeInterface $node) {
$build = $this->entityTypeManager
->getViewBuilder('node')
->view($node, 'pdf_using_mpdf');
$fileContent = $this->convert
->convertToString($this->renderer
->render($build));
$response = new Response($fileContent);
$disposition = $response->headers
->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $this->convert
->getFilename());
$response->headers
->set('Content-Disposition', $disposition);
$response->headers
->set('Content-type', 'application/pdf');
return $response;
}