Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement custom fonts in TCPDF

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

like image 866
Alfred Avatar asked Mar 10 '11 17:03

Alfred


People also ask

How do you embed custom fonts?

Open the file you want to embed fonts in. On the application (PowerPoint or Word) menu, select Preferences. In the dialog box, under Output and Sharing, select Save. Under Font Embedding, select Embed fonts in the file.

How do I use custom fonts in Swift UI?

To use a custom font, add the font file that contains your licensed font to your app, and then apply the font to a text view or set it as a default font within a container view. SwiftUI's adaptive text display scales the font automtically using Dynamic Type.


2 Answers

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

like image 120
Nicola Asuni Avatar answered Sep 20 '22 17:09

Nicola Asuni


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

like image 31
Yannis Avatar answered Sep 23 '22 17:09

Yannis