mpdf - using specific fonts


I am generating a pdf from my php web application...

I need to use a specific font in the pdf, and have some css for the font like this:	{ font-family: 'HelveticaNeueLT-BlackCond';     }

Open in new window

I have uploaded some fonts into the 'ttffonts' folder and I guess there must be more I need to do before I can use them in my pdfs... I have 3 fonts I need to use:

Who is Participating?
cycledudeConnect With a Mentor Author Commented:
Hey Dan

I think I got it working... not entirely sure how though...

I took out the 'en-x' from the first parameter in the constructor of the mpdf class

$size = 'A4';

$mpdf=new mPDF('',$size,'','',0,0,0,0,0,0);

and it fired up..
Dan CraciunIT ConsultantCommented:
After you uploaded the fonts to /ttfonts (not /ttffonts), did you also add entries for you fonts in config_fonts.php (in this->fontdata)?

Something like:
"Helvetica Condensed" => array(
"Helvetica Bold Condensed" => array(
"Helvetica Black Condensed" => array(
        'R' => "HelveticaNeueLT-BlackCond.ttf",

You would then use      { font-family: 'Helvetica Black Condensed';}

cycledudeAuthor Commented:

Thanks for the info..

I hadn't put the entry into the config_fonts.php  

I have now, and the fonts are in the correct folder (ttfonts)

but the font doesn't appear to be being selected as you would expect still

do I need corresponding files in the 'ttfontdata' folder too?
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Dan CraciunIT ConsultantCommented:
Not according to the manual:
cycledudeAuthor Commented:
i just tried changing the font selected to another in the 'fonts' array and it worked fine... it just doesn't want to play with my uploaded fonts at all..
Dan CraciunIT ConsultantCommented:
Have you tried them all?
I would expect troubles with the OpenType fonts, but not with the True Type one.
cycledudeAuthor Commented:
i have tried all 3 fonts I need to work, and a few others that I have uploaded but non seem to work....
Dan CraciunIT ConsultantCommented:
The fonts that do work, you can see them in the /ttfonts folder?
cycledudeAuthor Commented:

I tried the following test.. the only font from the ttfonts folder that seems to work is the monotype dejavumono (but even that may be a substitute font...)

page code


$html = "
		* { margin: 0 ; padding: 0; }
		.body { padding: 5%; float: left; margin: -140% 0 0 0; }
		p 	{ font-size: 30pt; margin: 0 0 0 7%; width: 60%; }
		.logo1	{ width: 15%; float: left; }
		.font1 { font-family: arial; }
		.font2 { font-family: tahoma; }
		.font3 { font-family: calibri; }
		.font4 { font-family: scriptina; }
		.font5 { font-family: dejavusansmono; }
		.font6 { font-family: HelveticaCondensed; }
		.font7 { font-family: helveticaboldcondensed; }
		.font8 { font-family: helveticablackcondensed; }

<div class='body'>
<p class='top font1' >Arial: abcdefghijklmnopqrstuvwxyz</p>
<p class='font2'>tahoma: abcdefghijklmnopqrstuvwxyz</p>
<p class='font3'>calibri: abcdefghijklmnopqrstuvwxyz</p>
<p class='font4'>scriptina: abcdefghijklmnopqrstuvwxyz</p>
<p class='font5'>dejavusansmono; abcdefghijklmnopqrstuvwxyz</p>
<p class='font6'>Helvetica Condensed; abcdefghijklmnopqrstuvwxyz</p>
<p class='font7'>helveticaboldcondensed; abcdefghijklmnopqrstuvwxyz</p>
<p class='font8'>helveticablackcondensed; abcdefghijklmnopqrstuvwxyz</p>



$mpdf=new mPDF('en-x',$size,'','',0,0,0,0,0,0);


Open in new window

and config_fonts.php

	"dejavusansmono" => array(
		'R' => "DejaVuSansMono.ttf",
		'B' => "DejaVuSansMono-Bold.ttf",
		'I' => "DejaVuSansMono-Oblique.ttf",
		'BI' => "DejaVuSansMono-BoldOblique.ttf",

	"HelveticaCondensed" => array(

	"helveticaboldcondensed" => array(
	"helveticablackcondensed" => array(
        'R' => "HelveticaNeueLT-BlackCond.ttf"

	"Scriptina" => array(
        'R' => "SCRIPTIN.ttf"

Open in new window

Dan CraciunIT ConsultantCommented:
I downloaded the test file and you have only Courier, Helvetica and Times-Roman inside.

So, mPDF is not reading any font from that folder, meaning it can't see the folder.

Does it generate some kind of log so we can see the errors?

This looks promising:
cycledudeAuthor Commented:
Hey thanks

I changed the value

$this->debugfonts = true;

but doesn't seem to show any errors... will they appear in a log or on the screen?
Dan CraciunIT ConsultantCommented:
I'm installing the package now in a test server. Will get back to you once I finish testing.
Dan CraciunConnect With a Mentor IT ConsultantCommented:
It's a font problem. Used a ttf variant of the Helvetica Condensed (LTe50052.ttf) and it worked, no issues.

I see you posted before this :) In my test page I don't have the "en-x" parameter.
Dan CraciunIT ConsultantCommented:
I think that behavior was intended. Look in config_cp.php. Particularly these lines:

           // Edit this value to define how mPDF behaves when using new mPDF('-x')
            // If set to TRUE, mPDF will use Adobe core fonts only when it recognises the languages above
            $coreSuitable = true;  break;

This means that your use of "en-x" forced mpdf to ignore any fonts you added.
cycledudeAuthor Commented:
thanks for the help dan, you da man ;o)
hey cycledude,

Your comment solve my issue!  :)
Shenkie KoelkastCommented:
cycledude! I don't know if you are still alive, but you are a hero!!

I had 'c' as first parameter, removing it made the custom font work, hurray!

Thanks alot!
Faye ArmisteadCommented:
Shenkie Koelkast - Mwah! That fixed mine! mwah
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.