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.
$html = view('pages.export', [
'page' => $page,
'format' => 'pdf',
$html = view('pages.export', [
'page' => $page,
'format' => 'pdf',
+ 'engine' => $this->pdfGenerator->getActiveEngine(),
])->render();
return $this->htmlToPdf($html);
])->render();
return $this->htmlToPdf($html);
'chapter' => $chapter,
'pages' => $pages,
'format' => 'pdf',
'chapter' => $chapter,
'pages' => $pages,
'format' => 'pdf',
+ 'engine' => $this->pdfGenerator->getActiveEngine(),
])->render();
return $this->htmlToPdf($html);
])->render();
return $this->htmlToPdf($html);
'book' => $book,
'bookChildren' => $bookTree,
'format' => 'pdf',
'book' => $book,
'bookChildren' => $bookTree,
'format' => 'pdf',
+ 'engine' => $this->pdfGenerator->getActiveEngine(),
])->render();
return $this->htmlToPdf($html);
])->render();
return $this->htmlToPdf($html);
+ const ENGINE_DOMPDF = 'dompdf';
+ const ENGINE_WKHTML = 'wkhtml';
+
/**
* Generate PDF content from the given HTML content.
*/
public function fromHtml(string $html): string
{
/**
* 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) {
+ if ($this->getActiveEngine() === self::ENGINE_WKHTML) {
$pdf = SnappyPDF::loadHTML($html);
$pdf->setOption('print-media-type', true);
} else {
$pdf = SnappyPDF::loadHTML($html);
$pdf->setOption('print-media-type', true);
} else {
+
+ /**
+ * 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;
+ }
+ @if($engine === \BookStack\Entities\Tools\PdfGenerator::ENGINE_DOMPDF)
+ {{-- Fix for full width linked image sizes on DOMPDF --}}
+ {{-- Undoes the above for table images to prevent visually worse scenario, Awaiting next DOMPDF release for patch --}}
+ .page-content td a > img {
+ max-width: 100%;
+ }
+ @endif
</style>
@endif
\ No newline at end of file
</style>
@endif
\ No newline at end of file
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>@yield('title')</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>@yield('title')</title>
- @include('common.export-styles', ['format' => $format])
+ @include('common.export-styles', ['format' => $format, 'engine' => $engine ?? ''])
@include('common.export-custom-head')
</head>
<body>
@include('common.export-custom-head')
</head>
<body>