mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-09 19:55:34 +08:00

Further fixes for #3120, Adds DOMPDF specific adjustments to prevent full width linked images being cut-off as per last tweak. This does not fix usage in smaller cases (tables) but tested on master DOMPDF branch shows that will likely be fixed in next DOMPDF upstream release. DOMPDF fixes would break WKHTMLTOPDF presentation so system updated to conditionally apply styles.
38 lines
993 B
PHP
38 lines
993 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Tools;
|
|
|
|
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
|
|
{
|
|
if ($this->getActiveEngine() === self::ENGINE_WKHTML) {
|
|
$pdf = SnappyPDF::loadHTML($html);
|
|
$pdf->setOption('print-media-type', true);
|
|
} else {
|
|
$pdf = DomPDF::loadHTML($html);
|
|
}
|
|
|
|
return $pdf->output();
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|