I'm using version 7.x of mPDF and tried to follow this documentation: https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
I just can't get it to work. No errors, but the font is still the default mPDF font. I also tried to do it another way with the answers from these:
How to generate PDF using mPDF and add custom Google font to it?
php mPDF, impossible to set font-family and font-size
But I guess they don´t work, as they might only be for older version than 7.X ...So here's is my latest attempt trying to use the information for the 7.x documentation.
Heres my php file:
require_once __DIR__ . '/vendor/autoload.php';
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/upload'],
['fontdata' => $fontData + [
'BentonSans' => [
'R' => 'BentonSans.ttf',
'I' => 'BentonSans-Bold.ttf',
]
],
'default_font' => 'BentonSans'
]);
$url = rawurldecode($_REQUEST['url']);
$html = file_get_contents($url);
$stylesheet = file_get_contents('style.css');
$mpdf->setBasePath($url);
$mpdf->AddFontDirectory('fonts');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output('filename.pdf','I');
And my css:
body {
font-family: 'BentonSans';
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: normal;
line-height: 20px;
}
My custom fonts are stored in "fonts" which is in the same folder as the php file.