pablinho
pablinho

Reputation: 213

How to add Open Sans font to mpdf document

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

This is the code I added to the previous files:

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?

Upvotes: 2

Views: 3405

Answers (1)

pablinho
pablinho

Reputation: 213

The problem was that I set 'c' into $mpdf = new mPDF('c');, that force the use of core fonts only, excluding the external fonts loaded from me.

Problem solved

Upvotes: 4

Related Questions