I am generating the PDF using TCPDF. The output I get is in Helvetica font but I want it in Frutiger. I have a frutiger.otf file.
I tried the following code
$fontname = $pdf->addTTFfont('Frutiger-45Light.otf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont($fontname);
I am getting an error: could not include font definition file. And I have googled many websites which didn't help.
You cannot use a URL as fontfile. It must be a path in the local filesystem.
If you need a font on a different server you first must download it yourself. Since fonts are static you should do this manually.
Related
I am using TCPDF library with CodeIgniter. How can I add Jameel Noori Nastaleeq fonts?
I have added Jameel_Noori_Nastaleeq.ttf font file under tcpdf\fonts folder, and included it like:
$fontname = $pdf->addTTFfont('/fonts/Jameel_Noori_Nastaleeq.ttf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('Jameel Noori Nastaleeq', 'BI', 20, '', 'false');
But it is not working. Anyone have an idea, how to include it?
I have applied jameel noori nastaleq font in my android studio app, it's working fine. I tried in this way:
set the name of the file without underscore(_) or dashes (-) with all small letters
don't use .ttf while giving a path of the font.
use this directory drawable/font
Hope this will help you.
I think problem is in path of your font. You must add font with full path. like
/home/username/public_html/...
try to upload your font in root path and locate it with this format.
/home/username/public_html/Jameel_Noori_Nastaleeq.ttf
Is better if you convert the font to ctg.z/z/php files. You can convert ttf fonts with http://fonts.palettize.me and then put uncompressed result in fonts folder into tcpdf class.
Then you can add it with $pdf->SetFont('jameelnoorinastaleeq', 'BI', 20);
I'm creating magento extension for pdf generating. I need to use Verdana Bold,Verdana Reg... fonts to my pdf file which generated using Zend_Pdf. Anyone can explain how to use the proper path for accessing TTF type fonts.
for this first you should upload desired font files into a directory best place to upload a font is inside lib folder so in this demonstration I will use create directory inside lib folder called customfonts and upload my font file there
Now call it on desired php file (ex: inside Shipment.php) and use it like below
$chevinFontBold = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/customfonts/chevin-bold.ttf');
$page->setFont($chevinFontBold, 8);
here 8 is the font size
//load font from file system
$font = Zend_Pdf_Font::fontWithPath("/path/to/myfont.ttf");
//add $font to page
$page->setFont($font, $fontSize);
Hope this helps
I would like to add a custom font to a pdf I'm generating using TCPDF. I might be missing something but the docs seem to be out dated. They are referencing the addTTFfont() function but I think it's been deprecated and no longer exists in the latest version of TCPDF.
I read that I need to convert the ttf file and put it in the fonts folder so I ran:
php/tcpdf/tools/tcpdf_addfont.php -i php/font/rumpelstiltskin-webfont.ttf
and it generated these files which are now in the fonts folder:
rumpelstiltskinwebfont.ctg.z
rumpelstiltskinwebfont.z
rumpelstiltskinwebfont.php
Then I tried to add the font:
$pdf->addFont('rumpelstiltskin');
$pdf->SetFont('rumpelstiltskin', '', 14, '', false);
but I'm getting an error:
TCPDF ERROR: Could not include font definition file: rumpelstiltskin
I figured out my issue, I was almost there.
Here is a step by step:
First convert your font using the tcpdf_addfont.php tool font in the TCPDF tools folder:
php/tcpdf/tools/tcpdf_addfont.php -i php/font/rumpelstiltskin-webfont.ttf
This will generate the required files and put them in the TCPDF fonts folder. Check the fonts folder and copy the name of the font, in my case it was rumpelstiltskinwebfont.
In your code set the font using the font file's name and write a line of text:
$pdf->SetFont('rumpelstiltskinwebfont', '', 14, '', false);
$pdf->Write(0, 'Fill text', '', 0, '', true, 0, false, false, 0);
That's it. Hope this helps someone. :)
Got this answer in another question and resolved for me. You just need to use the first parameter, the path of the font file. Worked with TTF and OTF fonts.
It generates a name string to use with $pdf->SetFont($fontname, '', $font_size);
Hope it helps.
The latest TCPDF version automatically convert fonts into TCPDF format using the addTTFfont() method. For example:
// convert TTF font to TCPDF format and store it on the fonts folder
$fontname = TCPDF_FONTS::addTTFfont('/path-to-font/FreeSerifItalic.ttf', 'TrueTypeUnicode', '', 96);
// use the font
$pdf->SetFont($fontname, '', 14, '', false);
For further information and examples, please check the TCPDF Fonts documentation page.
NOTE: Once the font has been converted, TCPDF no longer requires the TTF file or the above call to addTTFfont()!
You can convert ttf fonts with http://fonts.palettize.me and then put uncompressed result in fonts folder into tcpdf class. Then you can add it with $pdf->SetFont('rumpelstiltskinwebfont', '', 14); using the name of the file
Since TCPDF (version 6.2.6) you can use TCPDF_FONTS::addTTFfont directly instead of AddFont.
TCPDF makes three files out of the ttf and puts them into the directory "font" of TCPDF. Once these have been created, they can be used for all future PDFs.
Example:
First (for simplicity) I created a folder in the font folder of TCPDF with the name of the new font, in my example "arialuni" and copied my ttf of this font into it.
If I want to create my font files in a single separate file that does not use Composer autoload, I have to include TCPDF once and also specify the correct path to my ttf.
require_once('vendor/tecnickcom/tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$fontname = TCPDF_FONTS::addTTFfont('vendor/tecnickcom/tcpdf/fonts/arialuni/arialuni.ttf', 'TrueTypeUnicode', '', 32);
I am a web programmer with no in-depth knowledge of fonts and am struggling to get TCPDF to include our custom OpenType font. We have bought OpenType font files (.oft), which are not protected by any kind of DRM.
A lot of questions regarding this error message end up getting the same advice. I've set the correct file permissions for the folders used by TCPDF (755) and I have no trouble using the addTTFfont() to including .ttf TrueType fonts like so:
$pdf->addTTFfont('/path-to-font/DejaVuSans.ttf', 'TrueTypeUnicode', '', 32);
So I've made up the following code to include our OpenFont type. The addTTFfont() documentation seems to indicate support of OpenTypeUnicode and OpenType parameters.
$pdf->addTTFfont('/path-to-font/customfont.otf', 'OpenTypeUnicode', '', 96);
Which results in:
TCPDF ERROR: Could not include font definition file:
We're using TCPDF v6.0.020 and I've been reading the TCPDF Fonts information page with no luck so far. I've noticed TCPDF also has the addFont() function (documentation here) which seems more obvious to use as it does not include any reference to any font type. However, I was unable to get this function to work with the little documentation it has.
Any help would be greatly appreciated.
Are you sure that you are getting that error when calling addTTFfont()? The reason I ask is because I checked the TCPDF code (just did a global search on "Could not include font definition file") and that message only appears in the addFont() method.
These two methods can be a bit confusing, but I wrote myself some notes a few months ago, which I will partially reproduce below in the hope that it helps you somehow:
addTTFfont() - The primary function of this method is to convert a font from TTF (or OTF) to the "raw" version that TCPDF needs. The way this function is implemented you could, in theory, use it as your primary method of adding fonts to a document. It will check the tcpdf font folder first and if the converted files aren't there it will go ahead and do the conversion. It is only a little bit more overhead, but still not my preferred method of adding fonts to files, as you need to know what style of font you are converting for the process to even work successfully. IMO, it is better to use this method to pre-convert any fonts that you plan on using and simply use addFont() to add the "raw" versions to the document.
AddFont() - This adds a "raw" (ie. already converted) font to the document, which means it is then available for writing text.
SetFont() - This sets the font for the next chunk of text that you write.
So I would use addTTFfont() to pre-convert the font to the "raw" version, then use addFont() and setFont() in the code that actually creates the PDF.
If addFont() is failing with the error message above, it means it cannot find the font definition file. Keep in mind that if you call addFont() with style set ('i', 'b', 'bi', etc), all it does is append this to the file name (before the extension).
Most importantly, you need to make sure that your call to addTTFFont() is producing the "raw" font files and saving them into your fonts folder. There should be three files per style, with extensions of .php, .z and .ctg.z. So if you converted a font called blah.ttf you will end up with blah.php, blah.z and blah.ctg.z. If you convert blah bold.ttf, TCPDF will figure out that it is a bold font and append the 'b' to the end of the file names: blahb.php, blahb.z and blahb.ctg.z.
Hopefully there will be some nugget in here that will help! Good luck!
TCPDF New Font add and turkish char problem solved method.
Use Converter Link:
http://fonts.snm-portal.com
Download 3 files,
Copy TCPDF-master/fonts
Useage: $pdf->SetFont('roboto', '', 14);
To solve this problem with generating font.
Make sure all path are correct.
Use this link
Remember to put folder make_font inside folder of html2pdf
Remember about correct path to: html2pdf.class.php
inside folder make_font in index.php
or
If you have other problem - font: Could not include font definition file:
It's a problem of correct name of your new font.
For example using when generating pdf:
Correct: $html2pdf->addFont('lato i', '', 'latoi.php');
Incorrect: $html2pdf->addFont('lato', '', 'latoi.php');
Remember there are only 2 files generated:
latoi.php
latoi.z
You don't need any ctg file.
I hope it will help
In my case the problem was, that the fonts path wasn't writable. I fixed it by changing permissions of the folder: var_dump(K_PATH_FONTS);
In my case, it was simply a wrong path to the (no more found) .ttf font file.
For a test I used the drive D:/ successfully, but I forgot to change it back to the prod drive C:/ in my php file in the code line where I use the addTTFfont('C:/...') command.
Unfortunately, the TCPDF error message doesn't output anything about the source file and the code line producing the problem.
add the dejavusans.php file into the font folder into the tcpdf library into the codeingiter library folder.
"cid0jp" this font supports Japanese and Chinese.
I'm using the TCPDF library to generate a PDF file with PHP. I want to use a custom font so I used the addTTFfont method to add my custom TrueType font files. The font I am trying to add is "Aller" from fontsquirrel.com
$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueTypeUnicode', '', 32);
This created the files aller_rg.php, aller_rg.ctg.z, and aller_rg.z in my TCPDF fonts folder. The K_PATH_FONTS constant points to this directory. The addTTFfont method returns the string name of the font. It would return false if there was an error so the problem is probably not here..
I then tried to use the font
$pdf->SetFont($aller, '', 16); // or $pdf->SetFont('aller_rg', '', 16);
$pdf->Write(0,"abcdefg",'',0,'L',true,0,false,true,0);
The pdf is generated without any errors. When viewsed in the browser preview the font is clearly not aller but just a generic sans-serif.. When I open the pdf in Mac's Preview application the sections that are using the aller font are blank (no text displays).
Anyone know what I'm doing wrong?
Got it to work by using this tool
http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
it generates a .php, .z, and .afm file that you put in the TCPDF fonts directory. I'm still not sure what the problem was. the addTTFfont() method doesn't create the .afm file so maybe that's it?
I had the same problem:
The TCPDF converted font did not display, but the one converted with the following link did:
http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
So I compared the two and found out that xml-convert.com was using "TrueType" instead of "TrueTypeUnicode" as font type. For me it worked to change the argument to "TrueTypeUnicode". Try:
$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueType', '', 32);