我是mPDF的新用户,实际上我想为我的项目添加Times New Roman,因为mPDF不提供它。因此,我开始寻找方法,并找到了这些https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html。我尝试在我的代码上实现它,但是输出文件仍然无法加载字体。这是我的代码
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/font',
]),
'fontdata' => $fontData + [
'times' => [
'R' => 'times.ttf',
'I' => 'timesi.ttf',
'B' => 'timesbd.ttf',
'BI' => 'timesbi.ttf',]],
'default_font' => 'times']);
$mpdf = new \Mpdf\Mpdf($hal1config);
$stylesheet = '<style>' . file_get_contents('./gaya.css') . '</style>';
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($hal1, 2);
$mpdf->AddPage($hal2config);
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($hal2, 2);
谢谢
您需要:
$mpdf = new \Mpdf\Mpdf($hal1config);
'tempDir' =>
DIR]添加到配置数组中。 '/ custom / temp / dir / path'`,看我的示例加载字体
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__ . '/custom/temp/dir/path',
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/fonts',
]),
'fontdata' => $fontData + [
'roboto-condensed' => [
'R' => 'RobotoCondensed-Regular.ttf',
'B' => 'RobotoCondensed-Bold.ttf',
]
],
'default_font' => 'roboto-condensed'
]);
$mpdf->WriteHTML('<h1>Стенгазета</h1>');
$mpdf->Output();