How to implement custom fonts in TCPDF

后端 未结 13 707
鱼传尺愫
鱼传尺愫 2020-11-28 10:07

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??<

相关标签:
13条回答
  • 2020-11-28 10:57

    I found the addTTFfont method a little finicky (ok, probably didn't try very hard) and the online tool mentioned above works for FPDF but misses the ctg.z file that TCPDF requires.

    This one - http://fonts.snm-portal.com/ - generates the 3 required files (.php, .z and .ctg.z) for TCPDF. Convert the TTF, upload the three files to your fonts folder and you're good to go.

    0 讨论(0)
  • 2020-11-28 10:58

    When was not possible convert font GothamRounded standard way, I was looking for another tool and only this one http://fonts.snm-portal.com/ worked for me.

    0 讨论(0)
  • 2020-11-28 10:59

    First create .php ,.afm,.z from http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf and move all three in same directory containing .ttf file. then Use This :

    $pdf->AddFont(path-to/universe.ttf','',path-to/universe.php');
    $pdf->SetFont(path-to/universe.ttf','',10);
    
    0 讨论(0)
  • 2020-11-28 11:04

    I have discovered a very good tool online. The only thing you need to do is to upload your .ttf file and then download the files and copy then into the /fonts folder.

    https://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf

    0 讨论(0)
  • 2020-11-28 11:05

    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()!

    0 讨论(0)
  • 2020-11-28 11:05

    The addTTFfont method is not available on TCPDF main class so following worked for me.

    // convert TTF font to TCPDF format and store it on the fonts folder
    $fontname = TCPDF_FONTS::addTTFfont('pathto/arial.ttf', 'TrueTypeUnicode', '', 96);
    
    // use the font
    $pdf->SetFont($fontname, '', 14, '', false);
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题