X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/42703dd859f6eb1917c2547da106f0de646674a6..refs/pull/3238/head:/app/Entities/Tools/PdfGenerator.php diff --git a/app/Entities/Tools/PdfGenerator.php b/app/Entities/Tools/PdfGenerator.php index a14f29d4b..17a7da9f3 100644 --- a/app/Entities/Tools/PdfGenerator.php +++ b/app/Entities/Tools/PdfGenerator.php @@ -7,14 +7,15 @@ use Barryvdh\Snappy\Facades\SnappyPdf; class PdfGenerator { + const ENGINE_DOMPDF = 'dompdf'; + const ENGINE_WKHTML = 'wkhtml'; + /** * Generate PDF content from the given HTML content. */ public function fromHtml(string $html): string { - $useWKHTML = config('snappy.pdf.binary') !== false && config('app.allow_untrusted_server_fetching') === true; - - if ($useWKHTML) { + if ($this->getActiveEngine() === self::ENGINE_WKHTML) { $pdf = SnappyPDF::loadHTML($html); $pdf->setOption('print-media-type', true); } else { @@ -23,4 +24,15 @@ class PdfGenerator return $pdf->output(); } + + /** + * Get the currently active PDF engine. + * Returns the value of an `ENGINE_` const on this class. + */ + public function getActiveEngine(): string + { + $useWKHTML = config('snappy.pdf.binary') !== false && config('app.allow_untrusted_server_fetching') === true; + + return $useWKHTML ? self::ENGINE_WKHTML : self::ENGINE_DOMPDF; + } }