Module fpdf.annotations

Usage documentation at: https://py-pdf.github.io/fpdf2/Annotations.html

Classes

class AnnotationDict (subtype: str,
x: float,
y: float,
width: float,
height: float,
flags: tuple[AnnotationFlag | str, ...] = (<AnnotationFlag.PRINT: 4>,),
contents: str | None = None,
dest: Destination | PDFString | None = None,
action: Action | None = None,
color: tuple[float, float, float] | None = None,
modification_time: datetime.datetime | None = None,
title: str | None = None,
quad_points: Sequence[float] | None = None,
border_width: float = 0,
name: AnnotationName | FileAttachmentAnnotationName | None = None,
ink_list: tuple[float, ...] | None = None,
file_spec: FileSpec | str | None = None,
field_type: str | None = None,
value: str | None = None,
default_appearance: str | None = None)
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"

A PDF annotation that get serialized as an inline <>

Ancestors

Instance variables

var a
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var border
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var c
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var contents
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var d_a
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var dest
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var f
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var f_s
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var f_t
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var ink_list
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var name
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var p
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var quad_points
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var rect
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var subtype
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var t
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var type
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"
var v
Expand source code Browse git
class AnnotationDict(AnnotationMixin):
    "A PDF annotation that get serialized as an inline <<dictionary>>"

    __slots__ = (  # RAM usage optimization
        "type",
        "subtype",
        "rect",
        "border",
        "f_t",
        "v",
        "f",
        "contents",
        "a",
        "dest",
        "c",
        "t",
        "quad_points",
        "p",
        "name",
        "ink_list",
        "f_s",
        "d_a",
    )

    def serialize(
        self,
        _security_handler: Optional["StandardSecurityHandler"] = None,
        _obj_id: Optional[int] = None,
    ) -> str:
        obj_dict = build_obj_dict(
            {key: getattr(self, key) for key in dir(self)},
            _security_handler=_security_handler,
            _obj_id=_obj_id,
        )
        return pdf_dict(obj_dict)

    def __repr__(self) -> str:
        keys = [key for key in dir(self) if not key.startswith("__")]
        d = {key: getattr(self, key) for key in keys}
        d = {key: value for key, value in d.items() if not callable(value)}
        return f"AnnotationDict(**{d})"

Methods

def serialize(self) ‑> str
Expand source code Browse git
def serialize(
    self,
    _security_handler: Optional["StandardSecurityHandler"] = None,
    _obj_id: Optional[int] = None,
) -> str:
    obj_dict = build_obj_dict(
        {key: getattr(self, key) for key in dir(self)},
        _security_handler=_security_handler,
        _obj_id=_obj_id,
    )
    return pdf_dict(obj_dict)
class AnnotationMixin (subtype: str,
x: float,
y: float,
width: float,
height: float,
flags: tuple[AnnotationFlag | str, ...] = (<AnnotationFlag.PRINT: 4>,),
contents: str | None = None,
dest: Destination | PDFString | None = None,
action: Action | None = None,
color: tuple[float, float, float] | None = None,
modification_time: datetime.datetime | None = None,
title: str | None = None,
quad_points: Sequence[float] | None = None,
border_width: float = 0,
name: AnnotationName | FileAttachmentAnnotationName | None = None,
ink_list: tuple[float, ...] | None = None,
file_spec: FileSpec | str | None = None,
field_type: str | None = None,
value: str | None = None,
default_appearance: str | None = None)
Expand source code Browse git
class AnnotationMixin:
    def __init__(
        self,
        subtype: str,
        x: float,
        y: float,
        width: float,
        height: float,
        flags: tuple[AnnotationFlag | str, ...] = DEFAULT_ANNOT_FLAGS,
        contents: Optional[str] = None,
        dest: Optional[Destination | PDFString] = None,
        action: Optional[Action] = None,
        color: Optional[tuple[float, float, float]] = None,
        modification_time: Optional[datetime] = None,
        title: Optional[str] = None,
        quad_points: Optional[Sequence[float]] = None,
        border_width: float = 0,  # PDF readers support: displayed by Acrobat but not Sumatra
        name: Union[AnnotationName, FileAttachmentAnnotationName, None] = None,
        ink_list: Optional[tuple[float, ...]] = None,  # for ink annotations
        file_spec: Optional[Union["FileSpec", str]] = None,
        field_type: Optional[str] = None,
        value: Optional[str] = None,
        default_appearance: Optional[str] = None,  # for free text annotations
    ) -> None:
        self.type = Name("Annot")
        self.subtype = Name(subtype)
        self.rect = f"[{x:.2f} {y - height:.2f} {x + width:.2f} {y:.2f}]"
        self.border = f"[0 0 {border_width}]"
        self.f_t = Name(field_type) if field_type else None
        self.v = value
        self.f = sum(tuple(AnnotationFlag.coerce(flag) for flag in flags))
        self.contents = PDFString(contents, encrypt=True) if contents else None
        self.a = action
        self.dest = dest
        self.c = f"[{color[0]} {color[1]} {color[2]}]" if color else None
        self.t = PDFString(title, encrypt=True) if title else None
        self.m = PDFDate(modification_time, encrypt=True) if modification_time else None
        self.quad_points = (
            pdf_list([f"{quad_point:.2f}" for quad_point in quad_points])
            if quad_points
            else None
        )
        self.p = None  # must always be set before calling .serialize()
        self.name = name
        self.ink_list = (
            ("[" + pdf_list([f"{coord:.2f}" for coord in ink_list]) + "]")
            if ink_list
            else None
        )
        self.f_s = file_spec
        self.d_a = default_appearance

Subclasses

class FileSpec (embedded_file: PDFEmbeddedFile,
basename: str,
desc: str | None = None,
af_relationship: AssociatedFileRelationship | None = None)
Expand source code Browse git
class FileSpec(PDFObject):

    def __init__(
        self,
        embedded_file: PDFEmbeddedFile,
        basename: str,
        desc: Optional[str] = None,
        af_relationship: Optional[AssociatedFileRelationship] = None,
    ):
        super().__init__()
        self.type = Name("Filespec")
        self.f = PDFString(basename)
        self.u_f = PDFString(basename)
        if desc:
            self.desc = PDFString(desc)
        if af_relationship:
            self.a_f_relationship = Name(af_relationship.value)
        self._embedded_file = embedded_file

    @property
    def e_f(self) -> str:
        return pdf_dict({"/F": pdf_ref(self._embedded_file.id)})

Ancestors

Instance variables

prop e_f : str
Expand source code Browse git
@property
def e_f(self) -> str:
    return pdf_dict({"/F": pdf_ref(self._embedded_file.id)})

Methods

def content_stream(self) ‑> bytes

Inherited from: PDFObject.content_stream

Subclasses can override this method to indicate the presence of a content stream

def serialize(self, obj_dict: Dict[str, object] | None = None) ‑> str

Inherited from: PDFObject.serialize

Serialize the PDF object as an obj<</>>endobj text block

class PDFAnnotation (*args: Any, **kwargs: Any)
Expand source code Browse git
class PDFAnnotation(AnnotationMixin, PDFObject):
    "A PDF annotation that get serialized as an obj<</>>endobj block"

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        super().__init__(*args, **kwargs)

A PDF annotation that get serialized as an obj<</>>endobj block

Ancestors

Methods

def content_stream(self) ‑> bytes

Inherited from: PDFObject.content_stream

Subclasses can override this method to indicate the presence of a content stream

def serialize(self, obj_dict: Dict[str, object] | None = None) ‑> str

Inherited from: PDFObject.serialize

Serialize the PDF object as an obj<</>>endobj text block

class PDFEmbeddedFile (basename: str,
contents: bytes,
desc: str = '',
creation_date: datetime.datetime | None = None,
modification_date: datetime.datetime | None = None,
mime_type: str | None = None,
af_relationship: AssociatedFileRelationship | None = None,
compress: bool = False,
checksum: bool = False)
Expand source code Browse git
class PDFEmbeddedFile(PDFContentStream):
    def __init__(
        self,
        basename: str,
        contents: bytes,
        desc: str = "",
        creation_date: Optional[datetime] = None,
        modification_date: Optional[datetime] = None,
        mime_type: Optional[str] = None,
        af_relationship: Optional[AssociatedFileRelationship] = None,
        compress: bool = False,
        checksum: bool = False,
    ):
        super().__init__(contents=contents, compress=compress)
        self.type = Name("EmbeddedFile")
        params: dict[str, object] = {"/Size": len(contents)}
        if creation_date:
            params["/CreationDate"] = PDFDate(creation_date, with_tz=True).serialize()
        if modification_date:
            params["/ModDate"] = PDFDate(modification_date, with_tz=True).serialize()
        if checksum:
            file_hash = hashlib.new("md5", usedforsecurity=False)
            file_hash.update(self._contents)
            hash_hex = file_hash.hexdigest()
            params["/CheckSum"] = f"<{hash_hex}>"
        if mime_type:
            self.subtype = Name(mime_type)
        self.params = pdf_dict(params)
        self._basename: str = basename  # private so that it does not get serialized
        self._desc: str = desc  # private so that it does not get serialized
        self._globally_enclosed: bool = True
        self._af_relationship: Optional[AssociatedFileRelationship] = af_relationship
        self._file_spec: Optional[FileSpec] = None

    def globally_enclosed(self) -> bool:
        return self._globally_enclosed

    def set_globally_enclosed(self, value: bool) -> None:
        self._globally_enclosed = value

    def basename(self) -> str:
        return self._basename

    def file_spec(self) -> "FileSpec":
        if not self._file_spec:
            self._file_spec = FileSpec(
                self, self._basename, self._desc, self._af_relationship
            )
        return self._file_spec

Ancestors

Methods

def basename(self) ‑> str
Expand source code Browse git
def basename(self) -> str:
    return self._basename
def content_stream(self) ‑> bytes

Inherited from: PDFContentStream.content_stream

Subclasses can override this method to indicate the presence of a content stream

def file_spec(self) ‑> FileSpec
Expand source code Browse git
def file_spec(self) -> "FileSpec":
    if not self._file_spec:
        self._file_spec = FileSpec(
            self, self._basename, self._desc, self._af_relationship
        )
    return self._file_spec
def globally_enclosed(self) ‑> bool
Expand source code Browse git
def globally_enclosed(self) -> bool:
    return self._globally_enclosed
def serialize(self, obj_dict: Dict[str, object] | None = None) ‑> str

Inherited from: PDFContentStream.serialize

Serialize the PDF object as an obj<</>>endobj text block

def set_globally_enclosed(self, value: bool) ‑> None
Expand source code Browse git
def set_globally_enclosed(self, value: bool) -> None:
    self._globally_enclosed = value