Mpdf: How to add Open Sans font to mpdf document

Created on 15 Aug 2016  路  3Comments  路  Source: mpdf/mpdf

I have this problem/would like to have this functionality

I'm trying to add Open Sans font to my mpdf document but without success.

These are mPDF and PHP versions I am using

This is a PHP code snippet I use

In mpdf/config_fonts.php:

$this->fontdata = array(
...
    "opensans" => array( 
        'R'  => "OpenSans-Regular.ttf",
        'B'  => "OpenSans-Semibold.ttf",
        'I'  => "OpenSans-LightItalic.ttf",
        'BI' => "OpenSans-Semibolditalic.ttf"
    ),
...
);

In the php output file I added this:

<html>
<head>
    <style>
    body {
        font-family: 'Open Sans';
        font-size: 10pt;
    }

I also already tried to write font-family: opensans, sans-serif;

I uploaded the files into the folder: root/plugins/mpdf/ttfonts/

I think I did everything correctly but didn't work, it use the first sans substitutive font.

Extra info: the mpdf folder is located at his path: root/plugins/ the php file is creating the pdf file is located at this path: root/template/folder/ inside it I declared these:

define('_MPDF_PATH','../../plugins/mpdf/');
include("../../plugins/mpdf/mpdf.php");

probably there is something wrong with the paths, but I don't find the solution.

In addition I can say that If I load the font-family: opensans, sans-serif;, inside the example examples/example02_CSS_styles.php that it works correctly.

How can I solve?

Most helpful comment

Be sure you are not creating mPDF instance with c $mode parameter as this means core fonts only.

All 3 comments

Hi,

The following works for me:
<head>
<style type="text/css">
div,table { font-family: Open Sans, sans-serif !important;}
</style>
</head>

Be sure you are not creating mPDF instance with c $mode parameter as this means core fonts only.

Closing as stale.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nelhop picture nelhop  路  3Comments

azbatuk picture azbatuk  路  4Comments

Esc4pism picture Esc4pism  路  4Comments

BernhardBaumrock picture BernhardBaumrock  路  3Comments

huglester picture huglester  路  5Comments