[ACCEPTED]-FPDF error: Could not include font metric file-fpdf
I had the same issue. The issue was the 6 path was incorrect to the folder with all 5 of the fonts. So, I added updated the following 4 line in the PHP file to reflect the correct 3 path to the folder with all of the fonts.
define('FPDF_FONTPATH','class/fpdf_font/');
So, double 2 check the path that this line defines, and 1 it should work fine.
I belive you have already extracted fpdf 4 zip file onto your localhost or system
Once, zip 3 file is extracted you see directory structure 2 as in below image
and insert the below code 1 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
My problem was, because of downloading the 6 fpdf library from the page, some of the 5 scripts they have there uses Arial font 4 but, that font specially, was not included 3 in the fonts directory. I just added define('FPDF_FONTPATH','fpdf/font/');
with 2 relative path to the fpdf dir and changed 1 font to Courier and ready!
In my case I use Linux (Debian), I had the 3 same issue and the directories was right. I 2 solved adding 777 permissions to the /font 1 directory. And now it works like charm =)))
if you are using a external class that extends 6 FPDF
like file name Custom_pdf.php
in that file you wrote 5 your cutom codes
require_once('fpdf.php')
class Custom_PDF extends FPDF{
...
}
then you included in to 4 your coding like
require_once('custom_pdf.php');
$pdf = new Custom_pdf();
$pdf->Write();
....
$pdf->output();
this is problem...
So you 3 directly place the code in the file you 2 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 1 the english mistakes...
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.