Module fpdf.util

Various utilities that could not be gathered logically in a specific module.

The contents of this module are internal to fpdf2, and not part of the public API. They may change at any time without prior warning or any deprecation period, in non-backward-compatible ways.

Functions

def buffer_subst(buffer, placeholder, value)
def convert_unit(to_convert: Union[float, int, Iterable[Union[float, int, Iterable]]], old_unit: Union[str, numbers.Number], new_unit: Union[str, numbers.Number]) ‑> Union[float, tuple]

Convert a number or sequence of numbers from one unit to another.

If either unit is a number it will be treated as the number of points per unit. So 72 would mean 1 inch.

Args: to_convert (float, int, Iterable): The number / list of numbers, or points, to convert old_unit (str, float, int): A unit accepted by fpdf.FPDF or a number new_unit (str, float, int): A unit accepted by fpdf.FPDF or a number

Returns

(float, tuple): to_convert converted from old_unit to new_unit or a tuple of the same

def escape_parens(s)

Add a backslash character before , ( and )

def get_gc_managed_objs_total_size() ‑> str

From experiments, not very reliable

def get_mem_usage(prefix) ‑> str
def get_pillow_allocated_memory() ‑> str
def get_process_heap_and_stack_sizes() ‑> Tuple[str]
def get_process_rss() ‑> str
def get_process_rss_as_mib() ‑> Optional[numbers.Number]

Inspired by psutil source code

def get_pymalloc_allocated_over_total_size() ‑> Tuple[str]

Get PyMalloc stats from sys._debugmallocstats() From experiments, not very reliable

def get_scale_factor(unit: Union[str, numbers.Number]) ‑> float

Get how many pts are in a unit. (k)

Args

unit : str, float, int
Any of "pt", "mm", "cm", "in", or a number.

Returns

float
The number of points in that unit (assuming 72dpi)

Raises

ValueError

def get_tracemalloc_traced_memory() ‑> str

Requires python -X tracemalloc

def int2roman(n)

Convert an integer to Roman numeral

def print_mem_usage(prefix)

Classes

class Padding (top: numbers.Number = 0, right: numbers.Number = 0, bottom: numbers.Number = 0, left: numbers.Number = 0)

Padding(top, right, bottom, left)

Expand source code Browse git
class Padding(NamedTuple):
    top: Number = 0
    right: Number = 0
    bottom: Number = 0
    left: Number = 0

    @classmethod
    def new(cls, padding: Union[int, float, tuple, list]):
        """Return a 4-tuple of padding values from a single value or a 2, 3 or 4-tuple according to CSS rules"""
        if isinstance(padding, (int, float)):
            return Padding(padding, padding, padding, padding)
        if len(padding) == 2:
            return Padding(padding[0], padding[1], padding[0], padding[1])
        if len(padding) == 3:
            return Padding(padding[0], padding[1], padding[2], padding[1])
        if len(padding) == 4:
            return Padding(*padding)

        raise ValueError(
            f"padding shall be a number or a sequence of 2, 3 or 4 numbers, got {str(padding)}"
        )

Ancestors

  • builtins.tuple

Static methods

def new(padding: Union[int, float, tuple, list])

Return a 4-tuple of padding values from a single value or a 2, 3 or 4-tuple according to CSS rules

Instance variables

var bottom : numbers.Number

Alias for field number 2

var left : numbers.Number

Alias for field number 3

var right : numbers.Number

Alias for field number 1

var top : numbers.Number

Alias for field number 0