In TCPDF, there are only a few fonts to choose from, to create pdf files. I want to set Tahoma
as my pdf font. How can I include Tahoma
in TCPDF??<
I wasn't able to find addTTFFont() in the latest release of tcpdf.
However, I was able to include a custom TTF file by myself. Within the tcpdf folder is a folder named tools
which include a PHP file called tcpdf_addfont.php
.
I symlinked it to my home directory (you can omit this step) and run it like this:
shell
./addfont.php -b -t TrueTypeUnicode -f 32 -i myfont.ttf
That's it, it will dump something similar to this: ```
Converting fonts for TCPDF: *** Output dir set to /Users/pascalraszyk/XXX/XXX/pdf/vendor/tecnick.com/tcpdf/fonts/ +++ OK : /Users/pascalraszyk/XXX/XXX/pdf/myfont.ttf added as myfont Process successfully completed! ```
Note: There are more examples within the tools
folder for various font types.
I used composer to checkout tcpdf.
As long as you put your font definition files in the tcpdf/fonts
folder you should be good to go!
I used HTML2PDF which uses tcpdf under the hood and it worked like a charm.
I had this problem despite having all the right files. I had to change the file names to all lower case
the below lines will generate 3 files in ur fonts folder 1.rotisserifi56.php 2.rotisserifi56.ctg 3.rotisserifi56.rar
use this to generate the required php and other files
$fontname = $this->pdf->addTTFfont('D:/wamp/www/projectname/sites/all/modules/civicrm/packages/tcpdf/fonts/Rotis Serif Italic 56.ttf', 'TrueTypeUnicode', '', 32);
// use the font
$this->pdf->SetFont($fontname, '', 14, '', false);
Now,
use the fonts like this:
$this->pdf->AddFont('rotisserifi56', '', 'rotisserifi56.php');
$this->pdf->SetFont('rotisserifi56');
--hope this helps some one :)
Latest TCPDF supports custom fonts.
Documentation about using custom fonts with TCPDF can be read here.
the best way i have been tried and worked 100%
put your TTF
font in fonts folder and then use this constant K_PATH_FONTS + FONT NAME
$font1 = $this->pdf->addTTFfont(K_PATH_FONTS . 'arial.ttf', 'TrueTypeUnicode', '', 8);
$this->pdf->SetFont($font1, '', 15, '', false);
There is no point in using addTTFfont() if you don't have the .ttf file.
And the whole point is: if there is NO ttf file, how can someone use addTTFfont() function?
For example, there is no cid0cs file in font/ directory (TCPDF 6.0.20), only cid0cs.php, which is NOT a font file.