FPDF 错误:无法包含字体规格文件

发布于 2024-11-17 14:31:27 字数 680 浏览 5 评论 0原文

我有一个由其他人完成的应用程序,现在我被要求调查一个问题。

生成 pdf 报告时会抛出错误。此应用程序使用 FPDF 生成 PDF

FPDF error: Could not include font metric file

早些时候,它抛出以下错误

Warning: FPDF::include(helveticab.php) [function.FPDF-include]: failed to open stream: No such file or directory 
Warning: FPDF::include() [function.include]: Failed opening 'helveticab.php' for inclusion 
FPDF error: Could not include font metric file

这是通过包含包含 helveticab.php 的字体文件夹和与其他字体相关的其他 php 文件来解决的

但错误 FPDF 错误:无法包含字体度量文件仍然存在。 在网上搜索可能的原因是

  1. 字体目录丢失

  2. 没有字体文件的访问权限。

我不确定需要向字体文件夹或文件夹中的文件授予什么权限。 在这方面的任何帮助都会有很大帮助。

I have a app which was done by someone else and now i am asked to look into one issue.

When a pdf report is generated it throws an error. This app uses FPDF to generate the PDF

FPDF error: Could not include font metric file

Earlier it was throwing the following error

Warning: FPDF::include(helveticab.php) [function.FPDF-include]: failed to open stream: No such file or directory 
Warning: FPDF::include() [function.include]: Failed opening 'helveticab.php' for inclusion 
FPDF error: Could not include font metric file

This was resolved by including a font folder with helveticab.php and other php files related to other fonts

But the Error FPDF error: Could not include font metric file is still there.
On searching the net the possible reasons were

  1. font directory missing

  2. Doesnt have access permissions for the font files.

I am not sure what permission need to given to the font folder or files in the folder.
Any help in this regard would be of great help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

野侃 2024-11-24 14:31:27

我有同样的问题。问题是包含所有字体的文件夹的路径不正确。因此,我在 PHP 文件中添加了更新的以下行,以反映包含所有字体的文件夹的正确路径。

定义('FPDF_FONTPATH','class/fpdf_font/');

因此,请仔细检查该行定义的路径,它应该可以正常工作。

I had the same issue. The issue was the path was incorrect to the folder with all of the fonts. So, I added updated the following line in the PHP file to reflect the correct path to the folder with all of the fonts.

define('FPDF_FONTPATH','class/fpdf_font/');

So, double check the path that this line defines, and it should work fine.

雪化雨蝶 2024-11-24 14:31:27

我相信您已经将 fpdf zip 文件提取到本地主机或系统

上一旦提取了 zip 文件,您就会看到如下图所示的目录结构

在此处输入图像描述

并在 test.php 中插入以下代码

<?php
define('FPDF_FONTPATH','font/');
//above line is import to define, otherwise it gives an error : Could not include font metric file
require('fpdf.php');



$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

现在享受

I belive you have already extracted fpdf zip file onto your localhost or system

Once, zip file is extracted you see directory structure as in below image

enter image description here

and insert the below code in test.php

<?php
define('FPDF_FONTPATH','font/');
//above line is import to define, otherwise it gives an error : Could not include font metric file
require('fpdf.php');



$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

Now enjoy

自在安然 2024-11-24 14:31:27

我的问题是,由于从页面下载 fpdf 库,他们那里的一些脚本使用 Arial 字体,但是,特别是该字体,未包含在字体目录中。我刚刚添加了 define('FPDF_FONTPATH','fpdf/font/'); 以及 fpdf 目录的相对路径,并将字体更改为 Courier 并准备就绪!

My problem was, because of downloading the fpdf library from the page, some of the scripts they have there uses Arial font but, that font specially, was not included in the fonts directory. I just added define('FPDF_FONTPATH','fpdf/font/'); with relative path to the fpdf dir and changed font to Courier and ready!

清风无影 2024-11-24 14:31:27

就我而言,我使用 Linux (Debian),我遇到了同样的问题,并且目录是正确的。我解决了向 /font 目录添加 777 权限。现在它就像魅力一样起作用=)))

In my case I use Linux (Debian), I had the same issue and the directories was right. I solved adding 777 permissions to the /font directory. And now it works like charm =)))

强辩 2024-11-24 14:31:27

如果您使用扩展 FPDF 的外部类,

如文件名 Custom_pdf.php

在该文件中,您编写了自定义代码

require_once('fpdf.php')


class Custom_PDF extends FPDF{
   ...
}

,那么您将其包含到您的编码中,就像

require_once('custom_pdf.php');
$pdf = new Custom_pdf();
$pdf->Write();
....
$pdf->output();

这是问题......

所以您直接将您需要的文件中的代码

require_once('fpdf.php')
class Custom_PDF extends FPDF{
....
}
$pdf = new Custom_pdf();
$pdf->Write();
...
$pdf->output();

它会正常工作...

感谢

抱歉英语错误...

if you are using a external class that extends FPDF

like file name Custom_pdf.php

in that file you wrote your cutom codes

require_once('fpdf.php')


class Custom_PDF extends FPDF{
   ...
}

then you included in to your coding like

require_once('custom_pdf.php');
$pdf = new Custom_pdf();
$pdf->Write();
....
$pdf->output();

this is problem...

So you directly place the code in the file you need

require_once('fpdf.php')
class Custom_PDF extends FPDF{
....
}
$pdf = new Custom_pdf();
$pdf->Write();
...
$pdf->output();

it will works fine...

Thanks

sorry for the english mistakes...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文