Huh, Firefox just crashed and then all of macOS … weird.
I’m not using that line. My file looks like … see below.
So now, after that forced reboot, typing en/concept-paper.pdf
in my address bar results in a loading time of ~three minutes and then the following error:
I tried removing the color values from the CSS block in site/templates/default.pdf.php
, but the same error is thrown, so that’s probably not the problem.
Seems like some problem with mpdf
itself? Maybe I have to return to simply using <button onClick="window.print()">Save as PDF</button>
… 
<?php
use Mpdf\Mpdf;
use Mpdf\Config\ConfigVariables;
use Mpdf\Config\FontVariables;
use Mpdf\Output\Destination;
// load custom fonts
$assets = kirby()->roots()->assets();
$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$myFontDirs = array_filter(glob("$assets/fonts/*"), 'is_dir');
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
// init a pdf document
$pdf = new Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'fontDir' => array_merge($fontDirs, $myFontDirs),
'fontdata' => $fontData + [
'Inter' => [
'R' => 'Inter-Medium.otf',
'I' => 'Inter-MediumItalic.otf',
'B' => 'Inter-Bold.otf',
'BI' => 'Inter-BoldItalic.otf',
]
]
]);
// define some CSS for your ticket layout
$css = <<<CSS
:root {
--color-fg: cmyk(0,0,0,100);
--color-bg: cmyk(0,0,0,0);
--color-hi: cmyk(0,0,0,100);
--color-lo: cmyk(0,0,0,40);
--margin: 1rem;
--width: 64ch;
}
html {
font-family: Inter;
font-size: 10pt;
}
header > nav,
body > footer {
display: none;
}
main article h2 {
break-after: avoid;
}
main article h2 + p {
break-before: avoid;
}
main article p,
main article ul,
main article img {
break-inside: avoid;
}
main blockquote footer {
font-size: 10pt;
}
@page {
margin-left: 2.6cm;
margin-top: 2cm;
margin-right: 2cm;
margin-bottom: 2.6cm;
}
CSS;
// capture some html to be written on the ticket
ob_start(); ?>
<?php snippet('header') ?>
<?php snippet('nav') ?>
<main>
<article>
<?= $page->text()->toBlocks() ?>
</article>
<aside id="credits">
<div>
<?= $page->authors()->toBlocks() ?>
</div>
<div>
<?= $page->translators()->toBlocks() ?>
</div>
</aside>
</main>
<?php snippet('footer') ?>
<?php
// save the captured html to this variable
$html = ob_get_clean();
// give the document a title and an author name
$pdf->SetTitle($site->title() . ' - ' . $page->title());
$pdf->SetAuthor($site->title());
// write the css to the file
$pdf->WriteHTML($css, 1);
// write content to the file
$pdf->WriteHTML($html);
// you can also write the HTML to a fixed box
// the numbers are the bounds of the box in mm
// $pdf->WriteFixedPosHTML($html, 10, 10, 100, 100);
// respond with the pdf file
$pdf->Output($page->uid() . '.pdf', Destination::INLINE);