Search code examples
htmlcodeigniterpdfmozillampdf

Error No font or default font set in mpdf 6.1


I'm using codeigneiter in my system and mpdf 6.1 to generate pdf. When i'm adding new font in ttfont, then i get eror "No font or default font set!", code in my html to print:

$mpdf = new mPDF('utf-8','A4','');
$mpdf->fontDir = './third_party/mPDF/ttfont/'; /* location to save new font */
$mpdf->fontdata['ampleSoft'] = array(
        'R' => "ampleSoft-bold.ttf",
        'B' => "AmpleSoft-Medium.ttf",
);

$mpdf->SetFont('ampleSoft');

And in file config_fonts i'm adding new code:

'ampleSoft' => array(
        'R' => 'AmpleSoft-Medium.ttf',
        'B' => 'ampleSoft-bold.ttf'
    )

What's wrong with that?


Solution

  • fontDir variable is not available in mPDF 6.x. Define the path in _MPDF_TTFONTPATH constant. You may need to duplicate used font files from the distribution to your custom directory.

    https://mpdf.github.io/fonts-languages/fonts-in-mpdf-6-x.html