Source code

Download source archive ↓

src/pypdf/annotations/_base.py

1from abc import ABC
2
3from ..constants import AnnotationFlag
4from ..generic import NameObject, NumberObject
5from ..generic._data_structures import DictionaryObject
6
7
8class AnnotationDictionary(DictionaryObject, ABC):
9    def __init__(self) -> None:
10        super().__init__()
11
12        from ..generic._base import NameObject  # noqa: PLC0415
13
14        # /Rect should not be added here as Polygon and PolyLine can automatically set it
15        self[NameObject("/Type")] = NameObject("/Annot")
16        # The flags were NOT added to the constructor on purpose:
17        # We expect that most users don't want to change the default.
18        # If they do, they can use the property. The default is 0.
19
20    @property
21    def flags(self) -> AnnotationFlag:
22        return AnnotationFlag(self.get(NameObject("/F"), 0))
23
24    @flags.setter
25    def flags(self, value: AnnotationFlag) -> None:
26        self[NameObject("/F")] = NumberObject(value)
27
28
29NO_FLAGS = AnnotationFlag(0)