DOMPDF - Class 'Font' not found

2019-06-16 12:44发布

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.

标签: php dompdf
8条回答
小情绪 Triste *
2楼-- · 2019-06-16 13:16

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;

查看更多
我想做一个坏孩纸
3楼-- · 2019-06-16 13:20

I fixed the issue by change dompdf/include/font_metrics.cls.php file as bellow

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

copy past this code on top

查看更多
姐就是有狂的资本
4楼-- · 2019-06-16 13:21

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

查看更多
欢心
5楼-- · 2019-06-16 13:23

I hope this will help someone.

In case you get this error,

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

You have to change dompdf/include/font_metrics.cls.php file as below. So it will look like;

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 the second & third lines only. First one will be already there.

查看更多
别忘想泡老子
6楼-- · 2019-06-16 13:32

I figured out what it was.

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

查看更多
何必那么认真
7楼-- · 2019-06-16 13:32

I got this working for version DomPDF v6.1 by adding

use FontLib\Font;

to the file font_metrics.cls.php above

class Font_Metrics {
查看更多
登录 后发表回答