TCPDF SetFont and writeHTML

tcpdf

I'm having a problem with TCPDF. My custom font (and any other included font) isn't working when using writeHTML.

$tcpdf = tcpdf_get_instance();
$fontname = $tcpdf->addTTFfont('/antiquariat/sites/default/files/fonts/tstar-regular-webfont.ttf', 'TrueTypeUnicode', '', 32);
$tcpdf->SetFont('tstarwebfont', '', 16);
$tcpdf->writeHTML($html);

Fonts won't change, even if I use "helvetica" or any other font.
Second thing is, that the custom font isn't generated at all, but in first place I struggle with that not even any other font is used.

Best Solution

This is how i did it using TCPDF:

  1. First, use this website to generate your .PHP file and .z file.
  2. Put those 2 files at the folder .../tcpdf/fonts.
  3. You will use the PHP name file one.
  4. To add your font to pdf object :

     $pdf->AddFont('yourfont1');        //custom font
     $pdf->AddFont('yourfont2');        //custom font
    

Now, to use it inside a writeHTML:

$html = '
        <style>
        h1 {
            font-family: yourfont1;
            font-size: 40pt;
            text-align:center;
        }

        </style>


    <h1>Testing FONT</h1>
    ';

$pdf->writeHTML($html, true, false, true, false, '');
Related Question