Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
- I'm using dompdf and downloaded it from here: https://github.com/dompdf/dompdf.
- I downloaded https://github.com/PhenX/php-font-lib and copied to my php-font-lib and updated the dompdf_config.inc.php to ensure the Font.php is referenced correctly.
- I disabled Auto-configure the PDF tool settings.
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
Comment #1
ajlow CreditAttribution: ajlow commentedComment #2
ajlow CreditAttribution: ajlow commentedOK, 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?
Comment #3
ericbellot CreditAttribution: ericbellot commentedYou 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.
Comment #4
jlea9378 CreditAttribution: jlea9378 commentedThanks 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
Comment #5
mrchristophy CreditAttribution: mrchristophy commentedMine 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
Comment #6
adamhunger CreditAttribution: adamhunger commentedSolved 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;
Comment #7
Yuri CreditAttribution: Yuri commented@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.
Comment #8
Yuri CreditAttribution: Yuri commentedComment #9
margunnarsson CreditAttribution: margunnarsson commentedSolved this by
Disabling "Keep the current theme CSS" under admin/config/user-interface/print/common
Comment #10
earthangelconsulting CreditAttribution: earthangelconsulting commentedsee 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!
Comment #11
earthangelconsulting CreditAttribution: earthangelconsulting commentedalso, don't forget to enable the module "dompdf library handler", that threw me for a little while.
Comment #12
rennevat CreditAttribution: rennevat commentedIn our case, resolved this by removing imported fonts in custom print.css
Comment #13
jcnventura CreditAttribution: jcnventura at Wunder commentedThis 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