2021-11-25 10:12:32 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Entities\Tools;
|
|
|
|
|
|
|
|
use Barryvdh\DomPDF\Facade as DomPDF;
|
2021-11-28 16:01:35 -05:00
|
|
|
use Barryvdh\Snappy\Facades\SnappyPdf;
|
2021-11-25 10:12:32 -05:00
|
|
|
|
|
|
|
class PdfGenerator
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
$pdf = SnappyPDF::loadHTML($html);
|
|
|
|
$pdf->setOption('print-media-type', true);
|
|
|
|
} else {
|
|
|
|
$pdf = DomPDF::loadHTML($html);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pdf->output();
|
|
|
|
}
|
2021-11-28 16:01:35 -05:00
|
|
|
}
|