-
Notifications
You must be signed in to change notification settings - Fork 662
Description
Problem Description
When using the PyMuPDF library to modify a PDF file, I'm trying to use add_redact_annot and apply_redactions to remove text in specific areas, then insert new text at those positions. I've noticed that after removing the text, a blank white rectangle remains. I'd like to remove this rectangle.
However, I'm encountering the following issue:
When calling the methods in the following order:
# Add a white rectangle covering the entire area
annot = page.add_redact_annot(search_rect, fill=(1, 1, 1))
page.apply_redactions()
page.delete_annot(annot)An error occurs when executing page.delete_annot(annot), with an error message related to the annotation "not being bound to the page".
If I change the call order and delete the annotation before applying the redaction:
annot = page.add_redact_annot(search_rect, fill=(1, 1, 1))
page.delete_annot(annot)
page.apply_redactions()Although no error occurs, the apply_redactions() function no longer has the effect of removing the text.
Expected Solution
I would like to understand the correct way to use add_redact_annot and apply_redactions in PyMuPDF to ensure that:
- Text in the specified areas can be successfully removed
- No white rectangle is left behind in the document
What is the correct method? Is there some additional step required after calling apply_redactions to handle or remove these white rectangles?
pymupdf 1.26.4
Windows11 10.0.26100
Python 3.11.9