I am getting the following error and was wondering if anyone can help me resolve it:

PHP Fatal error:  Class 'Font' not found in /Applications/MAMP/htdocs/example/sites/all/libraries/dompdf/include/font_metrics.cls.php on line 346

I have done the following:

Now, I would have thought this would have solved it in the config file:

require_once(DOMPDF_LIB_DIR . "/php-font-lib/src/FontLib/Font.php");

From looking at the Font.php, it looks like it uses namespacing:

namespace FontLib;

Is this the issue? Is there a way to rectify this without modifying the module code?

Thank you for your help!

Comments

ajlow’s picture

Issue summary: View changes
ajlow’s picture

OK, it is the namspacing, however doing some testing, I get the next error:

PHP Fatal error: Class 'FontLib\EOT\File' not found in /Applications/MAMP/htdocs/example/sites/all/libraries/dompdf/lib/php-font-lib/src/FontLib/Font.php on line 60

I have a feeling the latest dompdf and php-font-lib are not compatible for this module...

Now, would anyone know where I can get a compatible version of dompdf and php-font-lib for the module?

ericbellot’s picture

You don't use the last php-font-lib version.

I had the same problem with dompdf 0.6.1 and php-font-lib version 0.3.1.

I solved the problem by using php-font-lib version 0.2.2.

jlea9378’s picture

Thanks those tips helped a lot!

Just a reminder, don't forget to make the fonts directory writable. I ran into that problem as well...!
/sites/all/libraries/dompdf/lib/fonts

mrchristophy’s picture

Mine was working fine, and now isn't. Must be a namespace conflict with another module? Any idea how to fix?

EDIT: saw your comment about 0.2.2 - it works now, but the formatting has gone a bit off in the PDFs. Gahhhh

adamhunger’s picture

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;

Yuri’s picture

@adamhunger, what 'latest' pdf-font-lib did you use, from what location?
I applied your tips but that did not work form me, same error repeats.

Yuri’s picture

Category: Support request » Bug report
margunnarsson’s picture

Related issues: +#1611582: pdf page in empty

Solved this by
Disabling "Keep the current theme CSS" under admin/config/user-interface/print/common

earthangelconsulting’s picture

see https://www.drupal.org/node/2286335#comment-9124643 and https://www.drupal.org/node/2286335#comment-9764173

i just installed dompdf (version 0.6.1) under sites/all/libraries, installed php-font-lib (version 0.4) at /sites/all/libraries/dompdf-0.6.1/lib/php-font-lib (when you download dompdf-0.6.1 there is an empty folder called php-font-lib) and then changed line 334 of sites/all/libraries/dompdf-0.6.1/dompdf_config.inc.php from

require_once(DOMPDF_LIB_DIR . "/php-font-lib/classes/Font.php");

to

require_once(DOMPDF_LIB_DIR . "/php-font-lib/src/FontLib/Font.php");

your mileage may vary, but this worked for me!

earthangelconsulting’s picture

also, don't forget to enable the module "dompdf library handler", that threw me for a little while.

rennevat’s picture

In our case, resolved this by removing imported fonts in custom print.css

jcnventura’s picture

Status: Active » Closed (won't fix)

This is caused by downloading the source release of the dompdf library.. Please make sure to download full builds from https://github.com/dompdf/dompdf/releases