Deleting annotations of a specific type #1672
-
Hello, Used the below snippet to delete annotations, originally found here. annot = page.firstAnnot
while annot:
annot = page.delete_annot(annot) When looking for ways to only delete specific annotations found that the Sample PDF AnnotationTest1.pdf Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Link, annotations and fields are handled as 3 different object types by MuPDF - although PDF uses the same technical basis for all of them. Or do this: alist = [a for a in page.annots(types=(...))]
for a in alist:
page.delete_annot(a) |
Beta Was this translation helpful? Give feedback.
-
Thanks for this note @JorjMcKie, will certainly help in working more effectively with PDFs. Can you add clarity to this?
|
Beta Was this translation helpful? Give feedback.
Link, annotations and fields are handled as 3 different object types by MuPDF - although PDF uses the same technical basis for all of them.
So links and fields will not occur in iterator
page.annots()
. Similarly, only fields will occur inpage.widgets()
.Your example has a link and a (text) annotation. The link will not be returned in neither
page.annots()
norpage.delete_annot()
.You could simply modify your above
while
statement:while annot and annot.type[0] in (... applicable numeric annot types):
.Or do this: