Commit 505ab93 1 parent 1e0ecdd commit 505ab93 Copy full SHA for 505ab93
File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 6
6
"""
7
7
8
8
from pathlib import Path
9
+ from typing import Optional
10
+
9
11
from pypdf import PdfReader , PdfWriter
12
+ from pypdf .annotations import AnnotationDictionary
13
+ from pypdf .generic import ArrayObject
10
14
11
15
12
16
# Check if an annotation is manipulable.
13
- def is_manipulable (annot ) -> bool :
17
+ def is_manipulable (annot : AnnotationDictionary ) -> bool :
14
18
return annot .get ("/Subtype" ) not in ["/Link" ]
15
19
16
20
17
21
# Main function.
18
- def main (input_pdf : Path , output_pdf : Path ) -> None :
22
+ def main (input_pdf : Path , output_pdf : Optional [ Path ] ) -> None :
19
23
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 " )
21
25
input = PdfReader (input_pdf )
22
26
output = PdfWriter ()
23
27
output_pages = 0
24
28
# Copy only the pages with annotations
25
29
for page in input .pages :
26
- if not "/Annots" in page :
30
+ if "/Annots" not in page :
27
31
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 ):
29
34
continue
30
35
output .add_page (page )
31
36
output_pages += 1
You can’t perform that action at this time.
0 commit comments