Skip to content

Commit b0d92b3

Browse files
authored
MAINT: Add AnnotationFlag (#1746)
BUG: /Flags should have been /F - typo. Was never released, though.
1 parent 3da3b25 commit b0d92b3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pypdf/constants.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,21 @@ class PageLabelStyle:
440440
UPPERCASE_LETTER = "/A" # Uppercase letters
441441

442442

443+
class AnnotationFlag(IntFlag):
444+
"""See 12.5.3 "Anntation Flags"."""
445+
446+
INVISIBLE = 1
447+
HIDDEN = 2
448+
PRINT = 4
449+
NO_ZOOM = 8
450+
NO_ROTATE = 16
451+
NO_VIEW = 32
452+
READ_ONLY = 64
453+
LOCKED = 128
454+
TOGGLE_NO_VIEW = 256
455+
LOCKED_CONTENTS = 512
456+
457+
443458
PDF_KEYS = (
444459
AnnotationDictionaryAttributes,
445460
CatalogAttributes,

pypdf/generic/_annotations.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
22

3+
from ..constants import AnnotationFlag
34
from ._base import (
45
BooleanObject,
56
FloatObject,
@@ -12,6 +13,8 @@
1213
from ._rectangle import RectangleObject
1314
from ._utils import hex_to_rgb, logger_warning
1415

16+
NO_FLAGS = AnnotationFlag(0)
17+
1518

1619
def _get_bounding_rectangle(vertices: List[Tuple[float, float]]) -> RectangleObject:
1720
x_min, y_min = vertices[0][0], vertices[0][1]
@@ -145,8 +148,9 @@ def free_text(
145148

146149
@staticmethod
147150
def popup(
151+
*,
148152
rect: Union[RectangleObject, Tuple[float, float, float, float]],
149-
flags: int = 0,
153+
flags: AnnotationFlag = NO_FLAGS,
150154
parent: Optional[DictionaryObject] = None,
151155
open: bool = False,
152156
) -> DictionaryObject:
@@ -174,7 +178,7 @@ def popup(
174178
NameObject("/Subtype"): NameObject("/Popup"),
175179
NameObject("/Rect"): RectangleObject(rect),
176180
NameObject("/Open"): BooleanObject(open),
177-
NameObject("/Flags"): NumberObject(flags),
181+
NameObject("/F"): NumberObject(flags),
178182
}
179183
)
180184
if parent:

0 commit comments

Comments
 (0)