mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-23 19:03:18 +08:00

- Replaced iframe elements with anchor elements wrapped in a paragraph. - Extracted PDF generation action to seperate class for easier mocking within testing. - Added test to cover. For #3077
28 lines
632 B
PHP
28 lines
632 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Tools;
|
|
|
|
use Barryvdh\Snappy\Facades\SnappyPdf;
|
|
use Barryvdh\DomPDF\Facade as DomPDF;
|
|
|
|
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();
|
|
}
|
|
|
|
} |