无法在mpdf 7.x

时间:2018-01-19 11:49:15

标签: 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__ . '/../../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

的内联样式
font-family: Arial, sans-serif

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

是错误还是我在某处弄错了?

1 个答案:

答案 0 :(得分:0)

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