Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOMPDF - Class 'Font' not found

Tags:

php

dompdf

I'm trying to add a font via Command line.

Every time I try i get the following error.

Fatal error: Class 'Font' not found in 
/home/scripts/public_html/MarketingPalv2/load_font.php on line 139

I also get a similar error when I try to use @font-face

Fatal error: Class 'Font' not found in 
/home/scripts/public_html/MarketingPalv2/include/font_metrics.cls.php on line 346

Hope you guys can help.

like image 265
David Allen Avatar asked Mar 06 '14 13:03

David Allen


3 Answers

I figured out what it was.

I downloaded the newest version of php-font-lib but i needed a older version.

like image 195
David Allen Avatar answered Nov 15 '22 23:11

David Allen


I got this working for version 0.3.1 / 0.4 of pdf-font-lib (commit: b8af0ca) and DomPDF v6.1.0 (commit: c3527d9) by making a Font class that extends FontLib\Font;

<?php
class Font extends FontLib\Font {
    //this is a namespace fix:
}

And in the class where I use DomPDF:

require_once('lib/dompdf/include/autoload.inc.php');
require_once('lib/dompdf/lib/php-font-lib/src/FontLib/Autoloader.php');
require_once('dir/where/you/placed/the/file/Font.php');

Now the class Font is available in the global namespace.

I choose this approach because I'm in a bit more dynamic situation and didn't want to change/edit the original library since it is from the master branch and it is LGPL licensed.

However, note that DomPDF 0.7.0 beta, that is released on 1 May, is out of the box compatible with the latest pdf-font-lib. Check it out: https://github.com/dompdf/dompdf/releases/tag/v0.7.0-beta

like image 32
Daniel van der Garde Avatar answered Nov 15 '22 23:11

Daniel van der Garde


Solved this for dompdf 0.6.1 using latest pdf-font-lib by editing load_font.php and making the header look like:

require_once "dompdf_config.inc.php";

require_once "lib/php-font-lib/classes/Autoloader.php"; use FontLib\Font;

like image 2
Adam Hunger Avatar answered Nov 15 '22 23:11

Adam Hunger