Reputation: 67
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
Upvotes: 1
Views: 3294
Reputation: 715
mPDF 7.x does not support uppercase fonts. In such of situation, you must rename your font name to lowercase
$mpdf->fontdata = array(
"qanela" => array(
'R' => "qanelassoftregular.ttf",
'B' => "qanelassoftbold.ttf",
),
)
Upvotes: 1
Reputation: 6725
Your code sample is somehow weird:
fontDir
property, you must use mPDF 7.xnew \mPDF
suggests 6.x - 7.x has a namespaced signature new \Mpdf\Mpdf()
_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",
);
Upvotes: 1
Reputation: 41
You don't want to override the entire fontdata
array (which is what you are doing). Instead, add your new record on the end of it.
$mpdf->fontdata['qanelasSof'] = array(
'R' => "QanelasSoft-Regular.ttf",
'B' => "QanelasSoft-Bold.ttf",
);
Then ensure your TTF font files are stored in the ttfonts directory.
Upvotes: 1