Skip to content

Commit e74fb10

Browse files
wolfram77Lucas-C
andcommitted
pdate pdfly/extract_annotated_pages.py
Seems that the `| None` syntax is not valid with Python 3.8 Co-authored-by: Lucas Cimon <[email protected]>
1 parent 1e0ecdd commit e74fb10

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pdfly/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def update_offsets(
286286
],
287287
file_out: Annotated[
288288
Path, typer.Option("-o", "--output") # noqa
289-
] = None, # type: ignore
289+
] = None, # type: ignore[assignment]
290290
encoding: str = typer.Option(
291291
"ISO-8859-1",
292292
help="Encoding used to read and write the files, e.g. UTF-8.",

pdfly/extract_annotated_pages.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,31 @@
66
"""
77

88
from pathlib import Path
9+
from typing import Optional
10+
911
from pypdf import PdfReader, PdfWriter
12+
from pypdf.annotations import AnnotationDictionary
13+
from pypdf.generic import ArrayObject # noqa: TCH002
1014

1115

1216
# Check if an annotation is manipulable.
13-
def is_manipulable(annot) -> bool:
17+
def is_manipulable(annot: AnnotationDictionary) -> bool:
1418
return annot.get("/Subtype") not in ["/Link"]
1519

1620

1721
# Main function.
18-
def main(input_pdf: Path, output_pdf: Path) -> None:
22+
def main(input_pdf: Path, output_pdf: Optional[Path]) -> None:
1923
if not output_pdf:
20-
output_pdf = input_pdf.with_stem(input_pdf.stem + "_annotated")
24+
output_pdf = input_pdf.with_name(input_pdf.stem + "_annotated.pdf")
2125
input = PdfReader(input_pdf)
2226
output = PdfWriter()
2327
output_pages = 0
2428
# Copy only the pages with annotations
2529
for page in input.pages:
26-
if not "/Annots" in page:
30+
if "/Annots" not in page:
2731
continue
28-
if not any(is_manipulable(annot) for annot in page["/Annots"]):
32+
page_annots: ArrayObject = page["/Annots"] # type: ignore[assignment]
33+
if not any(is_manipulable(annot) for annot in page_annots):
2934
continue
3035
output.add_page(page)
3136
output_pages += 1

0 commit comments

Comments
 (0)