Commit 00fb53d 1 parent 1e0ecdd commit 00fb53d Copy full SHA for 00fb53d
File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
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
10
13
11
14
12
15
# Check if an annotation is manipulable.
13
- def is_manipulable (annot ) -> bool :
16
+ def is_manipulable (annot : AnnotationDictionary ) -> bool :
14
17
return annot .get ("/Subtype" ) not in ["/Link" ]
15
18
16
19
17
20
# Main function.
18
- def main (input_pdf : Path , output_pdf : Path ) -> None :
21
+ def main (input_pdf : Path , output_pdf : Optional [ Path ] ) -> None :
19
22
if not output_pdf :
20
23
output_pdf = input_pdf .with_stem (input_pdf .stem + "_annotated" )
21
24
input = PdfReader (input_pdf )
22
25
output = PdfWriter ()
23
26
output_pages = 0
24
27
# Copy only the pages with annotations
25
28
for page in input .pages :
26
- if not "/Annots" in page :
29
+ if "/Annots" not in page :
27
30
continue
28
31
if not any (is_manipulable (annot ) for annot in page ["/Annots" ]):
29
32
continue
You can’t perform that action at this time.
0 commit comments