Can not remove a box in the footer

I want to remove a text box in every page footer. I tried add_redact_annot and apply_redactionsand some ways, all items could be removed except that text box i really wanted.

PS: I can get and show this text box by blocks = page.get_text(“blocks”)

output.pdf (9.3 KB)

Hi @coolfun and welcome to the forum!

When you use add_redact_annotdo you define the rect that you get from page.get_text(“blocks”) for the footer text box as the area you want to redact?

Thanks for your help!

I tried several ways, the one is below:

for page in doc:
    for annot in page.annots():

        if annot.type[1] == 'Watermark':
            print(f'Annotation on page: {page.number} with type: {annot.type} and rect: {annot.rect}')
            page.add_redact_annot(annot)
    page.apply_redactions()
doc.ez_save(output_path, garbage=4)

that outputs:
Annotation on page: 0 with type: (25, 'Watermark') and rect: Rect(127.5009994506836, 775.54345703125, 480.9460144042969, 792.0874633789062)
Annotation on page: 1 with type: (25, 'Watermark') and rect: Rect(128.84500122070312, 776.7039794921875, 482.2909851074219, 793.2479858398438)
Annotation on page: 2 with type: (25, 'Watermark') and rect: Rect(128.60499572753906, 779.10400390625, 482.0509948730469, 795.6480102539062)
Annotation on page: 3 with type: (25, 'Watermark') and rect: Rect(128.36500549316406, 775.0239868164062, 481.8110046386719, 791.5679931640625)
Annotation on page: 4 with type: (25, 'Watermark') and rect: Rect(128.48500061035156, 775.7439575195312, 481.9309997558594, 792.2879638671875)
Annotation on page: 5 with type: (25, 'Watermark') and rect: Rect(128.36500549316406, 778.3839721679688, 481.8110046386719, 794.927978515625)
Annotation on page: 6 with type: (25, 'Watermark') and rect: Rect(128.48500061035156, 778.1439819335938, 481.9309997558594, 794.68798828125)

Process finished with exit code 0

I even tried that:

    rect = page.rect
    annot = page.add_redact_annot(rect) 
    page.apply_redactions()

but these footers are still there.

Aha - I didn’t realise they were watermark annotations. In this case you just need to remove the annotation by deleting them (you can’t redact annotations). So just do:

for annot in annots:
        if annot.type[1] == 'Watermark':
            print(f'Annotation on page: {page.number} with type: {annot.type} and rect: {annot.rect}')
            page.delete_annot(annot);

Thanks @Jamie_Lemon it works perfectly. I have read many documents on the site Document - PyMuPDF documentation, but I still feel difficult to understand how do these objects work about document, page, annot etc.

Fair enough & thanks for the feedback - perhaps an introduction to what these objects are in a PDF might be useful. I guess the docs are written with the assumption that people understand what all the objects are in PDF. However, not being able to redact an annotation though - that should probably be mentioned as it isn’t immediately obvious!

This assumption is normal, as a professional in the related fields it is a must to. However, a well-organized book is useful to a professional or to me happen to use it for some time.