DOMPDF - Class 'Font' not found

I am trying to add a font through the 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.

+8
php dompdf
source share
7 answers

I realized what it was.

I downloaded the latest version of php-font-lib, but I needed an older version.

+8
source share

I got this working for version 0.3.1 / 0.4 pdf-font-lib (commit: b8af0ca) and DomPDF v6.1.0 (commit: c3527d9) by creating 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'); 

The Font class is now available in the global namespace.

I choose this approach because I am a little more dynamic and do not want to change / edit the source library, since it is in the main branch, and this is the LGPL license.

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

+3
source share

This is resolved for dompdf 0.6.1 using the latest pdf-font-lib by editing load_font.php and making the title look like:

require_once "dompdf_config.inc.php";

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

+2
source share

I used dompdf-master V.0.6.1, I solved it

require_once "../lib/php-font-lib/classes/Autoloader.php"; use FontLib\Font; before font_metrics.cls.php when installing a new font

+1
source share

I got this working for DomPDF v6.1 by adding

 use FontLib\Font; 

to the font_metrics.cls.php file above

 class Font_Metrics { 
+1
source share

Hope this helps someone.

If you get this error,

 Fatal error: Class 'Font' not found in dompdf/include/font_metrics.cls.php on line xxx 

You need to modify the dompdf/include/font_metrics.cls.php as shown below. It will look like this:

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

You need to add only the second and third lines. The first will already be there.

0
source share

I fixed the problem by modifying the dompdf/include/font_metrics.cls.php file below:

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

copy this code at the top

0
source share

All Articles