1

Hi,

How to add / install custom fonts for Html2PDF.

I want to show all content in Gotham Book Font.

I dont know how to add / install this font in HTML2PDF.

Please advice asap.


Thank you!!
avatar

2

Just define your font in your css file or an additional

Your additional CSS file called print2pdf.cssbody { font-family: Arial, Helvetica, sans-serif; }

$css = '<style>'.file_get_contents('PATH TO FILE/print2pdf.css').'</style>'; /// here call you external css file $html = 'Your HTML Code'; $html2pdf->writeHTML($css.$html);

3

mmmm, does that mean that I cannot use a font in my html? I would like to be able to apply the font in the html and then run html2pdf. Currently if I use verdana in my html I get an errormessage that the font is not installed. I have uploaded the additional fonts of the pdf lib, but no success so far.

Does anybody has a sample to implement i.e. Verdana? I did something like this but get an error:


$html2pdf=new HTML2PDF('P','A4','en');
$fontname = $html2pdf->pdf->addTTFfont('fonts/verdana.ttf', 'TrueTypeUnicode', '', 32);



lib included Fatal error: Call to undefined method HTML2PDF_myPdf::addTTFfont() in C:\Program Files (x86)\NetMake\v7\wwwroot\scriptcase\app\sjintweb\registration_complete\registration_complete_apl.php on line 1513


I managed to get it running by creating the 3 necessary files by using a webutility and put it in the font's directory.

4

Hi,

Here is how i actually did it regarding my non-understanding of the documentation about this. By default you can use Arial, Times, Helvetica and so on...Verdana isn't there, so you need to embed the font.
FIRST :
Convert a font you need to embed.
use this to go fast if font is True Type (.ttf) http://www.fpdf.org/makefont/
if not follow this : http://www.fpdf.org/en/tutorial/tuto7.htm

If it works you generate a php file and a compressed version of your font
Paste them somewhere, e.g (YOURSITE/html2pdf/_tcpdf_5.0.002/fonts/ because it's default place for fonts in FPDF)

SECOND :
After you add the html2pdf object like you did ($html2pdf = new HTML2PDF())
write
$html2pdf->addFont('font_name_you_want_in_css', '', 'generated_file.php');
don't forget path if generated_file.php is not stored in default FPDF fonts folder.

THIRD : Use it commonly with css.

5

Bisent0, thank you for the information.

I used your instructions however when I included the font php, I receive the error of Notice: Undefined offset: 32 in ...\_tcpdf_5.0.002\tcpdf.php on line 7194

the undefined offset warning goes from 32 to 255

The related code in tcpdf.php:
$cw = &$font['cw'];
$s = '[';
for ($i = 32; $i < 256; ++$i) {
$s .= $cw[$i].' '; <--------- line 7194
}

just for curiosity I bypassed it by adding this line:
if(!isset($cw[$i])) $cw[$i]="";


this time I was able to create pdf and use the font but the font is corrupted (the encoding is wrong and the words are on top of each other)


I checked the pdf generated at http://www.fpdf.org/makefont/ and compared it to default dejavusans php at tcpdf fonts folder

dejavusans.php has 517 lines while the one I created has 24 lines (I tried with 6-7 fonts and it is same for all of them)

Do you have any ideas about this?

Thanks