【发布时间】:2019-03-13 12:31:38
【问题描述】:
我正在使用 7.x 版的 mPDF 并尝试遵循此文档: https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
我就是无法让它工作。没有错误,但字体仍然是默认的 mPDF 字体。 我还尝试用另一种方式来回答这些问题:
How to generate PDF using mPDF and add custom Google font to it?
php mPDF, impossible to set font-family and font-size
但我猜它们不起作用,因为它们可能只适用于比 7.X 更旧的版本......所以这是我尝试使用 7.x 文档信息的最新尝试。
这是我的 php 文件:
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');
还有我的 CSS:
body {
font-family: 'BentonSans';
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: normal;
line-height: 20px;
}
我的自定义字体存储在与 php 文件位于同一文件夹中的“字体”中。
【问题讨论】:
-
我在想我可能是
$mPDFO = new mPDF('utf-8', 'A4', 0, 'font name here', 10, 10, 10, 0, 0, 0, 'L');...但我不知道在我的$mpdf = new \Mpdf\Mpdf(['tem....中放置“字体名称”的位置