I am looking for a solution to set more than just one font for my PDF document which is created with tcpdf.
I want to do something like this:
$pdf->SetFont('verdana_bold', 'B', 12);
$pdf->SetFont('verdana', '', 12);
I need for my document a bold font and a regular font. The example above doesn't work. When I switch the two lines the text is all bold. When I use the example above the text is just regular.
I want to set the font-weight
with regular css stylesheets.
Hope you have a solution.
Go to their github page https://github.com/tecnickcom/tcpdf either download to desktop or git clone.
You may see this error when generating your PDF catalog: TCPDF ERROR: Could not include font definition file: arialmt. The error means that the font (in this example arialmt) is missing in the modules configuration files. You will therefore need to add the font in the corresponding folder.
You can use your custom fonts inside html like this:
$fontname=$pdf->addTTFfont('path/myfont.ttf', '', '', 32);
//echo $fontname;
$html='<span style="font-family:'.$fontname'.;font-weight:bold">my text in bold</span>: my normal text';
$pdf->writeHTMLCell($w=0,$h=0,$x=11,$y=201,$html,$border=0,$ln=0,$fill=false,$reseth=true,$align='L',$autopadding=false);
The lines below will generate 3 files in your fonts folder
rotisserifi56.php, rotisserifi56.ctg, rotisserifi56.rar
use this to generate the file
$fontname = $this->pdf->addTTFfont('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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With