Solved

mpdf - using specific fonts

Posted on 2014-04-09
18
4,710 Views
Last Modified: 2016-10-21
Hi

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:

p.top	{ 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:

HelveticaNeueLT-BlackCond.ttf
HELVETICANEUELT-BOLDCOND.OTF
HELVETICANEUELT-CONDENSED.OTF
0
Comment
Question by:cycledude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39990687
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(
        'R' => "HELVETICANEUELT-CONDENSED.OTF",
        ),
"Helvetica Bold Condensed" => array(
        'R' => "HELVETICANEUELT-BOLDCOND.OTF",
        ),
"Helvetica Black Condensed" => array(
        'R' => "HelveticaNeueLT-BlackCond.ttf",
        ),

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

HTH,
Dan
0
 

Author Comment

by:cycledude
ID: 39990822
Hi

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?
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39990827
Not according to the manual: http://mpdf1.com/manual/index.php?tid=453
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cycledude
ID: 39992130
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..
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39992139
Have you tried them all?
I would expect troubles with the OpenType fonts, but not with the True Type one.
0
 

Author Comment

by:cycledude
ID: 39992232
i have tried all 3 fonts I need to work, and a few others that I have uploaded but non seem to work....
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39992239
The fonts that do work, you can see them in the /ttfonts folder?
0
 

Author Comment

by:cycledude
ID: 39992327
Hi

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...)




http://your-website.co.uk/mpdf/


page code

<?php


$html = "
<html>
<head>
	<style>
		* { 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; }
		
	</style>
</head>
<body>

<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>

    

</body>
</html>
"; 
 
  
include("mpdf/mpdf.php");


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


$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
//==============================================================
//==============================================================
//==============================================================
?>

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(
		'R' => "HELVETICANEUELT-CONDENSED.OTF",
		
		),

	
		
	"helveticaboldcondensed" => array(
        'R' => "HELVETICANEUELT-BOLDCOND.OTF"
		 
        ),
		
	"helveticablackcondensed" => array(
        'R' => "HelveticaNeueLT-BlackCond.ttf"
		
        ),

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

Open in new window

0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39992406
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: http://mpdf1.com/manual/index.php?tid=466
0
 

Author Comment

by:cycledude
ID: 39992442
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?
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39992450
I'm installing the package now in a test server. Will get back to you once I finish testing.
0
 

Accepted Solution

by:
cycledude earned 0 total points
ID: 39992483
Hey Dan

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


http://your-website.co.uk/mpdf/

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..
1
 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 500 total points
ID: 39992484
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.
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39992510
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.
1
 

Author Closing Comment

by:cycledude
ID: 40001141
thanks for the help dan, you da man ;o)
0
 
LVL 2

Expert Comment

by:sumi_dev
ID: 41575365
hey cycledude,

Your comment solve my issue!  :)
0
 

Expert Comment

by:Shenkie Koelkast
ID: 41852180
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!
1
 

Expert Comment

by:Faye Armistead
ID: 41854032
Shenkie Koelkast - Mwah! That fixed mine! mwah
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question