Using FPDF error with font helveticab.php - php

Im attempting to use FPDF, on Windows and using the XAMPP server.
I keep running into this error:
Warning: include(helveticab.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\php\PEAR\fpdf.php on line 541
Warning: include() [function.include]: Failed opening 'helveticab.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\php\PEAR\fpdf.php on line 541
FPDF error: Could not include font metric file
Anyone have an idea of how this can be resolved?
Also, I have checked and helveticab.php is installed which is the answer given in similar questions that i looked at.
Thanks

Not sure why they did it, but if the font is "Arial" they change the font to Helvetica. One of the styles is "c". They append the style to the font, so it searches and adds the fonts and styles. Example is helvetica bold is helveticab, or helvetica italic bold is helveticabi, but helveticac does not exist. To circumvent this, I added the following lines in fpdf.php at around line 498. If the style is "c", we set the style to "":
Code the already have
// Test if one of the core fonts
if($family=='arial')
$family = 'helvetica';
Code I added:
if(stripos($style, "c")!==false)
$style='';

I encountered the same problem but what solves it was I uploaded a folder in the program folder with name font. inside the font folder, I added the following files:
helveticab.php, helvetica.php, helveticabi.php, helvetica-extracompressed.ttf, and helveticai.php
Font folder can be downloaded from https://github.com/Setasign/FPDF.
Just download all the files in https://github.com/Setasign/FPDF/tree/master/font and add them to your application.

Try to use another font instead of Arial as like : Helvetica
Hope this will solve the problem :)

Related

How to set font path in FPDF

I'm getting the following error:
include(/gravity/school/pdf/font/helveticab.php): failed to open stream: No such file or directory in C:\xamp\htdocs\gravity\school\pdf\fpdf.php on line 1144
Can anyone tell me how to set the fontpath?
You can place font file anywhere in your project folder, the best way to place font file is fpdf/fonts, Where fpdf is your library folder which you are using to generate PDFs. Then after set the fonts as below:
define('FPDF_FONTPATH','/Path/to/font');
require('fpdf.php');
// Arial bold 14
$pdf->SetFont('Arial','B',14);
You can refer official doc for more information: SetFont FPDF

PHP Excel 01simple-download-xlsx.php and 07reader.php giving different output

I am trying to run 2 example of PHPExcel
01simple-download-xlsx.php and 07reader.php
01simple-download-xlsx.php Working Perfect but this example 07reader.php is showing error mentioned below Why can't understand since last 4 hours.
Any one can kindly tell me why this is happening when the file is using same directory structure.
Warning: require_once(../Classes/PHPExcel/IOFactory.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Fatal error: require_once(): Failed opening required
'../Classes/PHPExcel/IOFactory.php'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Some of the examples (such as the 01* files) correctly use an absolute pathname __DIR__ . '../Classes/...' to include the main PHPExcel library, which means you don't need to be in the /Examples directory to run them.
Other examples (07reader.php included) simply use a relative pathname '../Classes/...'to include the main PHPExcel library, which means you do need to be in the /Examples directory to run them.
To resolve the issue, either ensure that you're in the /Examples folder when you run these files, or modify the include to use the absolute pathname.
I believe I've now fixed all of these example files to use the absolute pathname in the development branch on github.

FPDF error: Could not include font metric file

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
font directory missing
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.
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.
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
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
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!
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 =)))
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...

how can get the FPDF library

i have found some pdf file geneartion program in php. When i run it i get the following error Warning:
Warning: include(helveticab.php) [function.include]: failed to open stream: No such file or directory in E:\wamp\www\raj19\fpdf.php on line 789
Warning: include() [function.include]: Failed opening 'helveticab.php' for inclusion (include_path='.;C:\php5\pear') in E:\wamp\www\raj19\fpdf.php on line 789
FPDF error : Could not include font metric file
I think the fpdf.php is missing .I have searched on their site but i could not find the english version. can anyone provide me full link of english version?
helveticab.php is a font definition file, which is shipped with FPDF. Get it here:
http://www.fpdf.org/
Since your code is not able to locate font library, add this line to your code.
define('FPDF_FONTPATH','fpdf/font/');
All you have to do is to copy the entire folder, and check for "fonts" one. Go inside and search for the file you're looking for.
If nothing works. Try with $font = 'fonts/arial.ttf'; and in the "fonts" folder put the TTF file. If you don't know where to get it. Search in your explorer "fonts" and get the TTF file by dragging it to the fonts folder or copying it.
If doens't works, copy the code line where you're trying to call the font file.
Depends on where the library is in the root directory. if Is in the same place just use
$str = 'fpdf.php';
require($str);
if your output is in a directory called fpdf and your php output is in another directory i.e. mydoc, you need to go up one step
$str = '../fpdf.php';
if your php output is down 2 steps i.e. root/myfolder/mydoc/output.php then you need to up two steps $str = '../../fpdf/fpdf.php'; i'm assuming that you have your fpdf library in the folder root/fpdf/fpdf.php

dompdf with codeigniter

I followed this tutorial:
https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf
However, I can't seem to set the path right. On the config file of dompdf (config_dompdf.inc.php) I did the following:
define("DOMPDF_DIR", realpath(dirname('./system/plugins/dompdf/')));
I get this error:
Message: require_once(/var/www/myApp/system/plugins/include/functions.inc.php) [function.require-once]: failed to open stream: No such file or directory
Filename: dompdf/dompdf_config.inc.php
Line Number: 233
As per the tutorial, I placed the dompdf directory under system/plugins. But you can see above that on line 233, there is an error because of an incorrect path. How do I fix the path?
(define("DOMPDF_DIR", realpath(dirname('./system/plugins/dompdf/')));)
Thanks!
A custom loader that is on autoload is conflicting with DOMPDF, that's the reason it doesn't work. Switched to TCPDF since the custom loader is used by all controllers of the app.
this file take $_GET['input_file'] as the name of the file that should be converted to pdf
http://localhost/dompdf/dompdf.php?input_file=[nameofyourfile]
You only need to change the value of DOMPDF_DIR if you have moved dompdf_config.inc.php from its usual location in the dompdf directory. Otherwise, dompdf is already set up to populate that constant with the correct path. Based on the information you have provided I do not believe you should have modified the default value.

Categories