I try to create pdf file using tFPDF with custom font.
I put arial font inside font/unifont folder.
I use this code to create pdf file:
$pdf->AddFont('arialbd','','arialbd.ttf',true);
$pdf->SetFont('arialbd','',16);
$pdf->Cell(40,6, 'OÜ Kersti Võlu Koolituskeskus', 0, 1);
$pdf->SetFont('arialbd','',10);
$pdf->Cell(40,12,'REGISTREERIMISLEHT', 0, 1);
$pdf->Output('test.pdf', 'I');
It works well on localhost, but when I uploaded this file on server, it shows me an error:
Warning: fopen(C:\xampp\htdocs\koolitus\wp-content\plugins\koolitus\fpdf/font/unifont/arialbd.ttf)
I see that library tries to load a font from my localhost, but I don't even set a path, just use font name
How to add fonts properly?
Delete all *.php and *.dat files in font/unifont folder except ttfonts.php.
All this files will be re-created (with right path).
Another option: open every mtx.php file.
Replace the line (absolute path):
$ttffile='D:\xampp8\htdocs\test\include\tfpdf/font/unifont/DejaVuSansCondensed.ttf';
With (relative path):
$ttffile='include/tfpdf/font/unifont/DejaVuSansCondensed.ttf';
Related
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
I am using the tFPDF package
$pdf=new tFPDF();
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('DejaVu', '', 12);
and it used to work. I had to reupload the font folder and since then I get the error message
FPDF error: Undefined font: dejavu
but the file DejaVuSansCondensed.ttf is definitely in the fonts folder. I even changed the mod to 777 because I thought maybe access rights are the problem, but it is still not working. What else could cause this error?
okay I just found the solution sorry for the post.
https://stackoverflow.com/a/38520012/2311074
Delete all *.php and *.dat files in font/unifont folder except
ttfonts.php. All this files will be re-created (with right path).
I'm trying to implement mpdf in CodeIgniter according to this article: http://codeigniter.com/wiki/mPDF_with_Codeigniter
I did it exactly the same way that is described there, but I got an error:
mPDF Error - cannot find TTF TrueType font file - mpdf/ttfonts/DejaVuSansCondensed.ttf
But the file is there. I tested this both on a webserver and on localhost. I changed chmod, neither did that have an effect.
What can I do about it?
I found out what was wrong.
As recommended in the CodeIgniter Wiki, I first had _MPDF_PATH in mpdf.php set to:
if (!defined('_MPDF_PATH')) define('_MPDF_PATH','mpdf/');
After I changed it to the absolute path, everything worked. The absolute path looks like this:
if (!defined('_MPDF_PATH'))
define('_MPDF_PATH','/home/example.com/htdocs/ci/application/libraries/mpdf/');
I had the same problem.
I've found my problem was the font. It was corrupted
I've downloaded the font from internet and I've replaced it in the ttfonts folder.
Everything worked!
Instead of defining _MPDF_PATH like this...
if (!defined('_MPDF_PATH')) define('_MPDF_PATH','mpdf/');
Change path according to this one... this will work without any error if you placed mdpf directory in your libraries dir
if (!defined('_MPDF_PATH')) define('_MPDF_PATH', APPPATH .
'libraries/mpdf/');
Got same result after uploading library files (auto) converted to lowercase filenames by file manager.
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...
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