Package fpdf

Root module. Gives direct access to some classes defined in submodules:

Expand source code Browse git
"""
Root module.
Gives direct access to some classes defined in submodules:

* `fpdf.fpdf.FPDF`
* `fpdf.enums.Align`
* `fpdf.enums.TextMode`
* `fpdf.enums.XPos`
* `fpdf.enums.YPos`
* `fpdf.errors.FPDFException`
* `fpdf.fonts.FontFace`
* `fpdf.fpdf.TitleStyle`
* `fpdf.prefs.ViewerPreferences`
* `fpdf.template.Template`
* `fpdf.template.FlexTemplate`
"""

import warnings, sys

from .enums import Align, TextMode, XPos, YPos
from .errors import FPDFException
from .fpdf import (
    FPDF,
    TitleStyle,
    FPDF_FONT_DIR as _FPDF_FONT_DIR,
    FPDF_VERSION as _FPDF_VERSION,
)
from .fonts import FontFace
from .html import HTMLMixin, HTML2FPDF
from .prefs import ViewerPreferences
from .template import Template, FlexTemplate
from .deprecation import WarnOnDeprecatedModuleAttributes

try:
    # This module only exists in PyFPDF, it has been removed in fpdf2 since v2.5.7:
    # pylint: disable=import-self
    from . import ttfonts

    warnings.warn(
        "You have both PyFPDF & fpdf2 installed. "
        "Both packages cannot be installed at the same time as they share the same module namespace. "
        "To only keep fpdf2, run: pip uninstall --yes pypdf && pip install --upgrade fpdf2"
    )
except ImportError:
    pass  # no PyFPDF installation detected

FPDF_VERSION = _FPDF_VERSION
"Current fpdf2 version, also available as `__version__`"

FPDF_FONT_DIR = _FPDF_FONT_DIR
"Extra filesystem folder where fpdf2 looks for fonts files, after the current directory"

# Pattern from sir Guido Von Rossum: https://stackoverflow.com/a/72911884/636849
# > a module can define a class with the desired functionality, and then at
# > the end, replace itself in sys.modules with an instance of that class
sys.modules[__name__].__class__ = WarnOnDeprecatedModuleAttributes

__license__ = "LGPL 3.0"

__version__ = FPDF_VERSION

__all__ = [
    # Metadata:
    "__version__",
    "__license__",
    # Classes:
    "FPDF",
    "FPDFException",
    "FontFace",
    "Align",
    "TextMode",
    "XPos",
    "YPos",
    "Template",
    "FlexTemplate",
    "TitleStyle",
    "ViewerPreferences",
    # Deprecated classes:
    "HTMLMixin",
    "HTML2FPDF",
    # FPDF constants:
    "FPDF_VERSION",
    "FPDF_FONT_DIR",
]

__pdoc__ = {name: name.startswith("FPDF_") for name in __all__}

Sub-modules

fpdf.actions
fpdf.annotations
fpdf.bidi
fpdf.deprecation

Utilities to manage deprecation errors & warnings …

fpdf.drawing

Vector drawing: managing colors, graphics states, paths, transforms …

fpdf.encryption

Utilities to perform encryption following the PDF standards …

fpdf.enums
fpdf.errors
fpdf.fonts

Font-related classes & constants. Includes the definition of the character widths of all PDF standard fonts …

fpdf.fpdf
fpdf.graphics_state

Mixin class for managing a stack of graphics state variables …

fpdf.html

HTML renderer …

fpdf.image_datastructures
fpdf.image_parsing
fpdf.line_break

Routines for organizing lines and larger blocks of text, with manual and automatic line wrapping …

fpdf.linearization

This module is in work-in-progress state. Hint tables / hint streams have not been implemented yet, and there are a few "TODO" comment remaining. cf …

fpdf.outline

Quoting section 8.2.2 "Document Outline" of the 2006 PDF spec 1.7:

The document outline consists of a tree-structured hierarchy of outline items …

fpdf.output

This module contains the serialization logic that produces a PDF document from a FPDF instance. Most of the code in this module is used when …

fpdf.prefs
fpdf.recorder

A wrapper class to allow rewinding/replaying changes made to a FPDF instance …

fpdf.sign

Module dedicated to document signature generation …

fpdf.structure_tree

Quoting the PDF spec:

PDF’s logical structure facilities provide a mechanism for incorporating structural information about a document’s content …

fpdf.svg

Utilities to parse SVG graphics into fpdf.drawing objects …

fpdf.syntax

Classes & functions that represent core elements of the PDF syntax …

fpdf.table
fpdf.template

PDF Template Helpers for fpdf.py

fpdf.text_region
fpdf.transitions
fpdf.util

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

Global variables

var FPDF_FONT_DIR

Extra filesystem folder where fpdf2 looks for fonts files, after the current directory

var FPDF_VERSION

Current fpdf2 version, also available as __version__