pdfme.fonts
- pdfme.fonts.get_tounicode_cmap(cmap_mappings)
Method returns cmap for Unicode mappings.
- class pdfme.fonts.PDFFont(ref)
Bases:
ABCAbstract class that represents a PDF font.
- Parameters:
ref (str) – the name of the font, included in every paragraph and page that uses this font.
- registered_fonts = {}
- loaded_fonts = []
- property ref
Property that returns the name (ref) of this font.
- Returns:
the name of this font
- Return type:
str
- static register(font_family, mode, path)
Method for registering user defined custom fonts. The registered font would be loaded when required in the document.
- Parameters:
font_family – The font family name.
mode – The font mode. One of n, b, i, bi.
path – Font file path.
- abstract property base_font
Abstract property that should return this font’s base font name.
- Returns:
the base font name
- Return type:
str
- abstractmethod get_char_width(char)
Abstract method that should return the width of
charcharacter in this font.- Parameters:
char (str) – the character.
- Returns:
the character’s width.
- Return type:
float
- abstractmethod get_text_width(text)
Abstract method that should return the width of the
textstring in this font.- Parameters:
text (str) – the sentence to measure.
- Returns:
the sentence’s width.
- Return type:
float
- class pdfme.fonts.PDFStandardFont(ref, base_font, widths)
Bases:
PDFFontThis class represents a standard PDF font.
- Parameters:
ref (str) – the name of this font.
base_font (str) – the base font name of this font.
widths (dict) – the widths of each character in this font.
- property base_font
- get_char_width(char)
- get_text_width(text)
- add_font(base)
- class pdfme.fonts.PDFTrueTypeFont(ref, filename=None)
Bases:
PDFFontThis class represents a TrueType PDF font.
- Parameters:
ref (str) – the name of this font.
base_font (str) – the base font name of this font.
widths (dict) – the widths of each character in this font.
- property base_font
- get_char_width(char)
- get_text_width(text)
- load_font(filename)
Method to extract information needed by the PDF document about this font, from font file in
filenamepath.- Parameters:
filename (str) – font file path.
- Raises:
ImportError – if
fonttoolslibrary is not installed.
- add_font(base)
- encode_text(text)
- compute_char_widths()
- class pdfme.fonts.PDFFonts
Bases:
objectClass that represents the set of all the fonts added to a PDF document.
- get_font(font_family, mode)
Method to get a font from its
font_familyandmode.- Parameters:
font_family (str) – the name of the font family
mode (str) – the mode of the font you want to get.
n,b,iorbi.
- Returns:
an object that represents a PDF font.
- Return type:
- load_font(path, font_family, mode='n')
Method to add a TrueType font to this instance.
- Parameters:
path (str) – the location of the font file.
font_family (str) – the name of the font family
mode (str, optional) – the mode of the font you want to get.
n,b,iorbi.