duanliang1019 2017-09-02 21:06
浏览 195
已采纳

在mPDF中加载自己的字体的问题

I know that question is is asked not the first time but all the other threads havn't helped me to get it work. I trie to get my own font work in my mPDF call. In read that version 7 I can load my own font without changing the config_fonts.php. Here is my try:

$mpdf = new \mPDF('utf-8','A4','');

$mpdf->fontDir = './assets/fonts/';
$mpdf->fontdata = array(
    "qanela" => array(
        'R' => "QanelasSoft-Regular.ttf",
        'B' => "QanelasSoft-Bold.ttf",
    ),
);

$mpdf->SetFont('qanela');

with this code I get the errormessage

mPDF Error - Font is not supported - dejavusanscondensed.

it is called from

mpdf/vendor/mpdf/mpdf/mpdf.php

on Line 3809 with

if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) { throw new MpdfException('mPDF Error - Font is not supported - ' . $family . ' ' . $style); }

Hopefull someone can help me.

Cheers

  • 写回答

2条回答 默认 最新

  • duangou2046 2017-09-04 09:44
    关注

    Your code sample is somehow weird:

    • To be able to use fontDir property, you must use mPDF 7.x
    • Your creation of mpdf instance new \mPDF suggests 6.x - 7.x has a namespaced signature new \Mpdf\Mpdf()
    • In 6.x you can set your own font dir via setting _MPDF_SYSTEM_TTFONTS constant:

    define('_MPDF_SYSTEM_TTFONTS', './assets/fonts/');


    In read that version 7 I can load my own font without changing the config_fonts.php

    There is no config_fonts.php file in v 7. All changes to configuration can be done in constructor $config parameter or by altering fontdata property of mPDF instance after creation of the object - as you are trying to do. See below.


    Also, try to append your font settings to the fontData property instead of overriding its contents:

    $mpdf->fontdata['qanela'] = 
        array(
            'R' => "QanelasSoft-Regular.ttf",
            'B' => "QanelasSoft-Bold.ttf",
        );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色