FPDF 错误:无法在 PHP 中包含字体定义文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14459039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:18:41  来源:igfitidea点击:

FPDF error: Could not include font definition file in PHP

phpfpdf

提问by J.K.A.

I have bunch of images and I want to generate PDF of of all those images. I am using FPDFlibrary (version 1.7) for achieving this. But I am getting the following error:

我有一堆图像,我想生成所有这些图像的 PDF。我正在使用FPDF库(版本 1.7)来实现这一点。但我收到以下错误:

FPDF error: Could not include font definition file

I found some articles on google regarding this error and tried that but still problem persist.

我在谷歌上找到了一些关于这个错误的文章并尝试过,但问题仍然存在。

What should be the problem here? Where I am going wrong?

这里应该是什么问题?我哪里出错了?

回答by cbologna

I had a similar error and i share here because there is no documentation online.

我有一个类似的错误,我在这里分享,因为没有在线文档。

"FPDF error: Font file not found"

“FPDF 错误:找不到字体文件”

If you convert a ttf font file for use it in FPDF with the online utility (http://fpdf.fruit-lab.de) once you have downloaded the files you need (file.php, file.afm, file.z) you'll have to:

如果您在下载所需的文件(file.php、file.afm、file.z)后使用在线实用程序(http://fpdf.fruit-lab.de)转换 ttf 字体文件以在 FPDF 中使用它你必须:

1) put in font folder (or any other folder, but you should use this instruction define('FPDF_FONTPATH','yourpath/yourfolder/');)

1)放入字体文件夹(或任何其他文件夹,但您应该使用此说明define('FPDF_FONTPATH','yourpath/yourfolder/');

2) If you RENAME the files, you should open the file.php and search for "$file" which contains the name of the ".z" file and rename it properly.

2)如果你重命名文件,你应该打开file.php并搜索包含“.z”文件名称的“$file”并正确重命名。

回答by Diogo Silva

Maybe a bit too late, but I used to have that same problem and the solution was to simply give permissions to the /font/ folder...

也许有点晚了,但我曾经遇到过同样的问题,解决方案是简单地授予 /font/ 文件夹的权限......

Rookie mistake... 755 permissions did the trick for me.

新手错误... 755 权限对我有用。

回答by vinod

    define('FPDF_FONTPATH','font/');



check in above line for correct path from local folder to server.....
exactly it runs well

    define('FPDF_FONTPATH','font/');

require('fpdf.php');
class PDF extends FPDF
{
//Constructor (mandatory with PHP3)
function PDF()
{
     self::__construct();
}

public function __construct()
    {
        $this->FPDF();
    }


//Page header
function Header()
{
    //Logo
    //$this->Image('logo_pb.png',10,8,33);
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(80);
    //Title
    $this->Cell(30,10,'Title',1,0,'C');
    //Line break
    $this->Ln(20);
}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
}
echo "<br/>";
//Instanciation of inherited class
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Times','',12);

$pdf->Image('logo_pb.png',40,20,33);

$url="demo/ivv/doc.pdf";

$dir='C:/xampp/htdocs/laravel/public/pdf/';

$filename= time().'.pdf';

$content=$pdf ->Output($dir.$filename);

?>

回答by user2561735

You must create the font definition files for the fonts you are using.

您必须为正在使用的字体创建字体定义文件。

See here:

看这里:

http://www.fpdf.de/tutorials/7/

http://www.fpdf.de/tutorials/7/

回答by Harshad

Check your font path in AddFont function.

在 AddFont 函数中检查您的字体路径。

For example:

例如:

$fontInformation = pathinfo(WWW_ROOT . "files/files/font/file/" . $pdffile['font_file']);

$fontFileName = $fontInformation['filename'] . '.php';

//$pdf->fontpath = WWW_ROOT . "files/font/file/";


$pdf->AddFont($fontInformation['filename'], '', $fontFileName);

//set font for the entire document
$pdf->SetFont($fontInformation['filename'], '', 20);

This may solve your problem.

这可能会解决您的问题。

回答by Marcus Lesniak

I had this kind of problem and my issue was that I was using a linux web server and I made the mistake of not using the correct case in my references to my font files. After I changed "Arial" to "arial" the problem was resolved.

我遇到了这种问题,我的问题是我使用的是 linux web 服务器,我犯了一个错误,即在引用我的字体文件时没有使用正确的大小写。在我将“Arial”更改为“arial”后,问题就解决了。