diff --git a/pypdf/constants.py b/pypdf/constants.py index 9ecdf0e82..9f7327adf 100644 --- a/pypdf/constants.py +++ b/pypdf/constants.py @@ -440,6 +440,21 @@ class PageLabelStyle: UPPERCASE_LETTER = "/A" # Uppercase letters +class AnnotationFlag(IntFlag): + """See 12.5.3 "Anntation Flags".""" + + INVISIBLE = 1 + HIDDEN = 2 + PRINT = 4 + NO_ZOOM = 8 + NO_ROTATE = 16 + NO_VIEW = 32 + READ_ONLY = 64 + LOCKED = 128 + TOGGLE_NO_VIEW = 256 + LOCKED_CONTENTS = 512 + + PDF_KEYS = ( AnnotationDictionaryAttributes, CatalogAttributes, diff --git a/pypdf/generic/_annotations.py b/pypdf/generic/_annotations.py index 555bc206e..f9d0f3de6 100644 --- a/pypdf/generic/_annotations.py +++ b/pypdf/generic/_annotations.py @@ -1,5 +1,6 @@ from typing import TYPE_CHECKING, List, Optional, Tuple, Union +from ..constants import AnnotationFlag from ._base import ( BooleanObject, FloatObject, @@ -12,6 +13,8 @@ from ._rectangle import RectangleObject from ._utils import hex_to_rgb, logger_warning +NO_FLAGS = AnnotationFlag(0) + def _get_bounding_rectangle(vertices: List[Tuple[float, float]]) -> RectangleObject: x_min, y_min = vertices[0][0], vertices[0][1] @@ -145,8 +148,9 @@ def free_text( @staticmethod def popup( + *, rect: Union[RectangleObject, Tuple[float, float, float, float]], - flags: int = 0, + flags: AnnotationFlag = NO_FLAGS, parent: Optional[DictionaryObject] = None, open: bool = False, ) -> DictionaryObject: @@ -174,7 +178,7 @@ def popup( NameObject("/Subtype"): NameObject("/Popup"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Open"): BooleanObject(open), - NameObject("/Flags"): NumberObject(flags), + NameObject("/F"): NumberObject(flags), } ) if parent: