【问题标题】:unable to set arial font in mpdf 7.x无法在 mpdf 7.x 中设置 arial 字体
【发布时间】:2018-01-19 11:49:15
【问题描述】:

遵循此处描述的指南: 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__ . '/../../Resources/Public/Fonts',]),
        'fontdata' => $fontData + [
            'Arial' => [
                'R' => 'arial.ttf',
                'I' => 'arial.ttf',
            ]
        ],
        'default_font' => 'Arial'
    ]);

    $mpdf->WriteHTML($pdfTemplate->render());
    $mpdf->Output(__DIR__.'/document.pdf','F');

在模板中也有带有字体系列的内联样式

font-family: Arial, sans-serif

但是当我下载 pdf 并检查字体时,它们是默认的 DejaVuSansCondensed

是错误还是我在某个地方犯了错误?

【问题讨论】:

标签: mpdf


【解决方案1】:

很久以前,但我有同样的问题。 解决方案是“fontdata”(Arial)中的大写键。这应该是小写(arial)并且在 css 中使用:“font-family: arial, other-fallback-font”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2012-09-07
    • 2017-07-08
    • 2016-08-05
    • 2021-03-15
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多