3 namespace BookStack\Entities\Tools;
5 use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
6 use Barryvdh\Snappy\Facades\SnappyPdf;
10 const ENGINE_DOMPDF = 'dompdf';
11 const ENGINE_WKHTML = 'wkhtml';
14 * Generate PDF content from the given HTML content.
16 public function fromHtml(string $html): string
18 if ($this->getActiveEngine() === self::ENGINE_WKHTML) {
19 $pdf = SnappyPDF::loadHTML($html);
20 $pdf->setOption('print-media-type', true);
22 $pdf = DomPDF::loadHTML($html);
25 return $pdf->output();
29 * Get the currently active PDF engine.
30 * Returns the value of an `ENGINE_` const on this class.
32 public function getActiveEngine(): string
34 $useWKHTML = config('snappy.pdf.binary') !== false && config('app.allow_untrusted_server_fetching') === true;
36 return $useWKHTML ? self::ENGINE_WKHTML : self::ENGINE_DOMPDF;