fpdf.add_font(family: str, style = '', fname = '', uni = False)
Imports a TrueType, OpenType or Type1 font and makes it available.
Warning: for Type1 and legacy fonts it is necessary to generate a font definition file first with the
MakeFont utility. This feature is currently deprecated in favour of TrueType Unicode font support (whose fonts are automatically processed with the included
Note: the font source files must be accessible. They are searched successively in (if these constants are defined):
FPDF_FONTPATH(by default, the
fontfolder in the fpdf package directory)
If the file corresponding to the requested font is not found, the runtime exception "TTF Font file not found: ..." is raised.
For more information, see the Unicode support page.
This method should be called before the set_font method is used, and the font will be available for the whole document.
Note: due to the fact that font processing can occupy large amount of time, some data are cached.
Cache files are created in same folder by default. This can be changed by setting the
- 0 - (by default), store the cache in the same folder as the font file
- 1 - disable all caching
- 2 - store cache files in the
FPDF_CACHE_DIRdirectory with cryptic names
Font family. Used as a reference for set_font, for example:
Font style. Deprecated, maintained only for backward compatibility.
Font file name (e.g.
'DejaVuSansCondensed.ttf'). You can specify a full path; if not, the file will be searched in
TTF Unicode flag (if set to
True, TrueType font subset embedding will be enabled and text will be treated as
You must not call add_font for the standard PDF Latin-1 fonts (Courier, Helvetica, Times, Symbol, Zapfdingbats); use set_font directly in that case.
Calling this method with uni=False is discouraged as legacy font support is complex and deprecated.
# Add a Unicode free font pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True) # Add a Unicode system font (using full path) pdf.add_font('sysfont', '', r"c:\WINDOWS\Fonts\arial.ttf", uni=True)