From e7b3e69ed4146ba9c7c3d326c5526b0035bbec55 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 30 Sep 2021 15:18:26 +1000 Subject: [PATCH] Add a fallback PDF generator if one fails --- app/Jobs/Entity/CreateRawPdf.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Jobs/Entity/CreateRawPdf.php b/app/Jobs/Entity/CreateRawPdf.php index 564e19d8be54..585deb9dbe35 100644 --- a/app/Jobs/Entity/CreateRawPdf.php +++ b/app/Jobs/Entity/CreateRawPdf.php @@ -170,6 +170,15 @@ class CreateRawPdf implements ShouldQueue if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){ $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); + + $finfo = new \finfo(FILEINFO_MIME); + + //fallback in case hosted PDF fails. + if($finfo->buffer($pdf) != 'application/pdf; charset=binary') + { + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); + } + } else { $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));