FPDF error: Could not include font definition file in PHP

二次信任 提交于 2019-12-20 03:33:50

问题


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

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?


回答1:


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

"FPDF error: Font file not found"

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:

1) put in font folder (or any other folder, but you should use this instruction 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:


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...

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




回答3:


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

See here:

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




回答4:


    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);

?>



回答5:


Check your font path in AddFont function.

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.




回答6:


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.



来源:https://stackoverflow.com/questions/14459039/fpdf-error-could-not-include-font-definition-file-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!