]> BookStack Code Mirror - bookstack/blob - app/Entities/Tools/PdfGenerator.php
Started work on details/summary blocks
[bookstack] / app / Entities / Tools / PdfGenerator.php
1 <?php
2
3 namespace BookStack\Entities\Tools;
4
5 use Barryvdh\DomPDF\Facade as DomPDF;
6 use Barryvdh\Snappy\Facades\SnappyPdf;
7
8 class PdfGenerator
9 {
10     /**
11      * Generate PDF content from the given HTML content.
12      */
13     public function fromHtml(string $html): string
14     {
15         $useWKHTML = config('snappy.pdf.binary') !== false && config('app.allow_untrusted_server_fetching') === true;
16
17         if ($useWKHTML) {
18             $pdf = SnappyPDF::loadHTML($html);
19             $pdf->setOption('print-media-type', true);
20         } else {
21             $pdf = DomPDF::loadHTML($html);
22         }
23
24         return $pdf->output();
25     }
26 }