]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Tools/PdfGenerator.php
Updated minimum php version from 7.3 to 7.4
[bookstack] / app / Entities / Tools / PdfGenerator.php
index d606617a402d75409babb90c719e31b4a30384cc..17a7da9f30536f8bd6d39d5800cb41327e230775 100644 (file)
@@ -2,20 +2,20 @@
 
 namespace BookStack\Entities\Tools;
 
-use Barryvdh\Snappy\Facades\SnappyPdf;
 use Barryvdh\DomPDF\Facade as DomPDF;
+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 {
@@ -25,4 +25,14 @@ class PdfGenerator
         return $pdf->output();
     }
 
-}
\ No newline at end of file
+    /**
+     * 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;
+    }
+}