Skip to content

Commit

Permalink
Pdfexport: Generate PDF before modifying response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Mar 15, 2024
1 parent 9f551aa commit 5f08ecb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/Pdfexport/ProvidedHook/Pdfexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ public function streamPdfFromHtml($html, $filename)
{
$filename = basename($filename, '.pdf') . '.pdf';

// Generate the PDF before changing the response headers to properly handle and display errors in the UI.
$pdf = $this->htmlToPdf($html);

/** @var Web $app */
$app = Icinga::app();
$app->getResponse()
->setHeader('Content-Type', 'application/pdf', true)
->setHeader('Content-Disposition', "inline; filename=\"$filename\"", true)
->setBody($this->htmlToPdf($html))
->setBody($pdf)
->sendResponse();

exit;
Expand Down

0 comments on commit 5f08ecb

Please sign in to comment.