2013-01-22 45 views
0

我有一堆图像,我想生成所有这些图像的PDF。我正在使用FPDF库(版本1.7)来实现此目的。不过,我收到以下错误:FPDF错误:无法在PHP中包含字体定义文件

FPDF error: Could not include font definition file 

我发现在谷歌关于此错误的一些文章和尝试,但仍然问题仍然存在。

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

+2

http://stackoverflow.com/questions/6521000/fpdf-error-could-not-include-font-metric-file的可能的复制,还有更多... – Rikesh

+0

@Rikesh:我已经尝试过,但它不起作用 – Sky

+0

你有没有检查ttf扩展名是否大写? – wahmal

回答

0

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

例如:

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

这可能会解决你的问题。

4

也许有点晚了,但是我曾经有同样的问题,解决的办法是干脆放弃权限/字体/文件夹...

新秀错误... 755权限为我做了诡计。

4

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

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

如果转换一个TTF字库文件与在线工具(http://fpdf.fruit-lab.de)利用它在FPDF一旦你已经下载了你所需要的文件(file.php,文件.afm,file.z) 你必须:

1)放在字体文件夹(或任何其他文件夹,但你应该如果您重命名文件使用该指令define('FPDF_FONTPATH','yourpath/yourfolder/');

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

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

?>