1

I know how to do it to make it work in local environment, I added fonts .ttf to /vendor/mpdf/mpdf/ttfonts, and then added

$this->fontdata = array(
"calibri" => array(
'R' => 'calibri.ttf',
'B' => 'calibrib.ttf',
)
...

to /vendor/mpdf/config-fonts.php

So now I can use Calibri font in my pdfs, but what I should to to use it properly not only locally and after composer update?

4

1 回答 1

0

我找到的解决方案:

1)将.ttf字体放入/your/path/to/fonts/dir,添加custom_config.php以下内容:

$this->fontdata["calibri"] = [
    'R' => 'calibri.ttf',
    'B' => 'calibrib.ttf',
];

2) 在 common/configs 中使用自定义字体设置路径并使用自定义配置文件

'mpdfCustomFontsPath' => /your/path/to/custom_config.php,
'mpdfCustomFonts' => /your/path/to/fonts/dir,

3) 在创建 kartik/Pdf 实例之前,在您的代码中执行以下操作:

$customFontsConfig = Yii::$app->params['mpdfCustomFontsPath'];
$customFonts = Yii::$app->params['mpdfCustomFonts'];
define("_MPDF_SYSTEM_TTFONTS_CONFIG", $customFontsConfig);
define("_MPDF_SYSTEM_TTFONTS", $customFonts);

这将起作用,因为 mpdf 将在处理 html 到 pdf 时进行_MPDF_SYSTEM_TTFONTS_CONFIG检查_MPDF_SYSTEM_TTFONTS

于 2017-07-17T12:55:06.967 回答