Tojo Chacko
Tojo Chacko

Reputation: 1280

How to generate PDF using mPDF and add custom Google font to it?

I am generating PDF using mPDF PHP library. I am able to successfully generate it using the default font configuration. However, I want to render a Google font in my PDF. I tried using the steps mentioned in this link, but it did not work. Below is the code I use.

$mPDFO = new mPDF('utf-8', 'A4', 0, '', 10, 10, 10, 0, 0, 0, 'L');

Can anyone help me using Google Font in mPDF ?

Upvotes: 3

Views: 6311

Answers (1)

nimsrules
nimsrules

Reputation: 2064

As mentioned in mPDF's documentation, it's not possible to use remote fonts directly by referencing them in the HTML. Follow the below steps to use custom fonts:

  1. Download the fonts & upload them to mPDF's fonts directory /ttfonts

  2. Declare the font-family you need to use in config_fonts.php under: $this->fontdata

  3. Now comes the main part. You need to mention the font-family in the instance that you create to call mPDF's object which is what you missed, like so:

    $mPDFO = new mPDF('utf-8', 'A4', 0, 'Source Sans Pro', 10, 10, 10, 0, 0, 0, 'L');

  4. Finally call the SetFont method like $mPDFO->SetFont('Source Sans Pro'); just below your instance

Upvotes: 10

Related Questions