简体   繁体   English

MPDF 8+ google 字体未注册

[英]MPDF 8+ google font doesen't register

I want to use a google font with MPDF.我想在 MPDF 中使用谷歌字体。 I followed their instruction , step by step, but it doesn't work for me.我按照 他们的指示一步一步地进行,但它对我不起作用。 I register the MPDF object as following:我将 MPDF object 注册如下:

$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 + [
    'comfortaa' => [
        'R' => 'Comfortaa-Regular.ttf',
        'B' => 'Comfortaa-Bold.ttf',
    ]
],
]);

$mpdf->WriteHTML($html);

From google, I use the font Comfortaa.从谷歌,我使用字体 Comfortaa。 I downloaded it as a static TTF file, which google gives you the ability to.我将它下载为 static TTF 文件,谷歌让你能够这样做。 I used 400 version for Comfortaa-Regular.ttf and the 700 for Comfortaa-Bold.ttf.我为 Comfortaa-Regular.ttf 使用 400 版本,为 Comfortaa-Bold.ttf 使用 700 版本。 In the current folder, there is a folder called fonts .在当前文件夹中,有一个名为fonts的文件夹。

I'm declaring the CSS as inline style like this:我将 CSS 声明为这样的内联样式:

<td class="content-block powered-by" style="font-family: comfortaa; vertical-align: top; font-size: 13px; color: #b9b9b9; text-align: center;">
    Powered by <a href="https://example.com" style="font-size: 13px; text-align: center; color: #b9b9b9;"><strong style="text-decoration:none;"><span>Flowmarket</span></strong></a>.
</td>

But still, the font doesn't load.但是,字体仍然没有加载。 I get no error message too, so I don't know where to start.我也没有收到错误消息,所以我不知道从哪里开始。 Is it possible that the Google font has a wrong encoding?谷歌字体是否可能有错误的编码? I'm using MPDF Version 8.0.5.0.我正在使用 MPDF 版本 8.0.5.0。

Okay, this is kinda embarrassed I guess.好吧,我想这有点尴尬。 I was previewing the file on its location URL in chrome and you need to reset the browser cache in order to see the changes...我在 chrome 中预览其位置 URL 的文件,您需要重置浏览器缓存才能看到更改...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM