Skip to content

Is there any way to delete only 1 specific widget in a page? #2662

Closed Answered by pubpub-zz
ag-gaphp asked this question in Q&A
Discussion options

You must be logged in to vote

For me you should be able to loop through annotations and then delete it:
(should be something like this)

import pypdf
w = pypdf.PdfWriter(clone_from="input.pdf")
to_be_deleted = []
for i, a in enumerate(w.pages[0]["/Annots"]):
   a=a.get_object()
   if #### criteria on a ####:
       to_be_deleted.append(i)
for i in to_be_deleted[::-1]:
   del w.pages[0]["/Annots"][i]

w.write("output.pdf")

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ag-gaphp
Comment options

@pubpub-zz
Comment options

Answer selected by ag-gaphp
@ag-gaphp
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants