pdfme.fonts

class pdfme.fonts.PDFFont(ref)

Bases: abc.ABC

Abstract class that represents a PDF font.

Parameters

ref (str) – the name of the font, included in every paragraph and page that uses this font.

property ref

Property that returns the name (ref) of this font.

Returns

the name of this font

Return type

str

abstract property base_font

Abstract property that should return this font’s base font name.

Returns

the base font name

Return type

str

abstract get_char_width(char)

Abstract method that should return the width of char character in this font.

Parameters

char (str) – the character.

Returns

the character’s width.

Return type

float

abstract get_text_width(text)

Abstract method that should return the width of the text string in this font.

Parameters

text (str) – the sentence to measure.

Returns

the sentence’s width.

Return type

float

abstract add_font(base)

Abstract method that should add this font to the PDFBase instance, passed as argument.

Parameters

base (PDFBase) – the base instance to add this font.

class pdfme.fonts.PDFStandardFont(ref, base_font, widths)

Bases: pdfme.fonts.PDFFont

This 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

See pdfme.fonts.PDFFont.base_font()

get_char_width(char)

See pdfme.fonts.PDFFont.get_char_width()

get_text_width(text)

See pdfme.fonts.PDFFont.get_text_width()

add_font(base)

See pdfme.fonts.PDFFont.add_font()

class pdfme.fonts.PDFTrueTypeFont(ref, filename=None)

Bases: pdfme.fonts.PDFFont

This class represents a TrueType PDF font.

This class is not working yet.

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

See pdfme.fonts.PDFFont.base_font()

get_char_width(char)

See pdfme.fonts.PDFFont.get_char_width()

get_text_width(text)

See pdfme.fonts.PDFFont.get_text_width()

load_font(filename)

Method to extract information needed by the PDF document about this font, from font file in filename path.

Parameters

filename (str) – font file path.

Raises

ImportError – if fonttools library is not installed.

add_font(base)

See pdfme.fonts.PDFFont.add_font()

class pdfme.fonts.PDFFonts

Bases: object

Class 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_family and mode.

Parameters
  • font_family (str) – the name of the font family

  • mode (str) – the mode of the font you want to get. n, b, i or bi.

Returns

an object that represents a PDF font.

Return type

PDFFont

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, i or bi.