From 4a479e48db3740ade48a64e77b357243322deb89 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 25 Mar 2025 10:37:07 +0100 Subject: [PATCH] Pdf: Ensure dompdf can create temporary files This is required since dompdf seems to automatically load our custom font and complains otherwise. (cherry picked from commit 191444ccd9bb3ea8ef1a2502a8c981e3b66a98cd) --- library/Icinga/File/Pdf.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/Icinga/File/Pdf.php b/library/Icinga/File/Pdf.php index e159e2fce..8ccdb7bb8 100644 --- a/library/Icinga/File/Pdf.php +++ b/library/Icinga/File/Pdf.php @@ -5,9 +5,11 @@ namespace Icinga\File; use Dompdf\Dompdf; use Dompdf\Options; +use Exception; use Icinga\Application\Icinga; use Icinga\Exception\ProgrammingError; use Icinga\Util\Environment; +use Icinga\Web\FileCache; use Icinga\Web\Hook; use Icinga\Web\Url; @@ -79,8 +81,17 @@ class Pdf return; } + $tmpDir = FileCache::instance()->directory('legacy_pdf'); + if ($tmpDir === false) { + throw new Exception('Could not create temporary directory for PDF rendering'); + } + $options = new Options(); $options->set('defaultPaperSize', 'A4'); + $options->set('fontDir', $tmpDir); + $options->set('fontCache', $tmpDir); + $options->set('tempDir', $tmpDir); + $options->set('chroot', $tmpDir); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->render();