adding font to mPDF

Paul Dessert picture Paul Dessert · Jul 11, 2013 · Viewed 42k times · Source

I'm getting the following error when I try and generate a PDF using the mPDF class:

TTF file "C:/wamp/www/inc/mpdf/ttfonts/verdana.ttf": invalid checksum 20f65173c11 table: DSIG (expected 65173c11)

I've uploaded the font files to my ttfonts directory and defined the font in config_fonts.php like this:

"verdana" => array(
    'R' => "verdana.ttf",
    'B' => "verdanab.ttf",
    'I' => "verdanai.ttf",
    'BI' => "verdanaz.ttf",
    ),

I only see the error when I turn on font error reporting in the config settings. When I turn error reporting off, the PDF is generated, but the font being used is not Verdana.

Any idea on what I'm doing wrong?

Answer

Ajai picture Ajai · Jun 7, 2016

Following are the steps to add new font family in mpdf library:

  1. Download the font zip and unzip it.
  2. Add new newFont.ttf font file(s) to this location /mpdf/ttfonts folder.
  3. Edit /mpdf/config_fonts.php OR /mpdf/src/config/FontVariables.php to add an entry to the $this->fontdata array for the new font file(s). Like:

    $this->fontdata = array(
        "newFont" => array(
        'R' => "newFont-Regular.ttf",
        'B' => "newFont-Bold.ttf",
        'I' => "newFont-Italic.ttf",
        'BI' => "newFont-BoldItalic.ttf",
    ),
    
  4. font-family: 'newFont'; is now available in the stylesheets.

  5. $mpdfObj = new mPDF('', '', 'newFont'); $mpdfObj->SetFont('newFont');

  6. Now your new font is added.