Skip to content

Redacting results are not as expected in 1.24.x. #3376

@Marerc

Description

@Marerc

Description of the bug

Hi there! Thanks for the excellent software for manipulating PDF files.

I have encountered the same issue as #3375. I am using pymupdf to remove some information from a commerical report through code, as shown below:

from typing import List
from fitz import Rect, Page
import fitz
import os


def handlePDF(doc):
    content_footer_rect = Rect(0, 772, 595, 842) 
    content_header_rect = Rect(0, 0, 595, 70)    
    cover_footer_rect = Rect(0, 600, 595, 842)     
    cover_upper_rect = Rect(0, 0, 595, 140)        

    print(f"Handling PDF from Jianbo")
    print(f"Handling cover page")
    p0: Page = doc[0]
    p0.add_redact_annot(cover_upper_rect)
    p0.add_redact_annot(cover_footer_rect)
    p0.apply_redactions()

    print(f"Handling body")
    for page in doc:
        page.add_redact_annot(content_header_rect)
        page.add_redact_annot(content_footer_rect)
        page.apply_redactions()

    print(f"Handling tailpage")
    last_page = doc[len(doc) - 1]
    copyright_positions: List[Rect] = last_page.search_for("Copyright BGI All Rights Reserved")
    for rect in copyright_positions:
        last_page.add_redact_annot(Rect(0, rect.y0 - 10, 595, rect.y0 + 30)) 
        last_page.apply_redactions()
    return doc

folder = os.path.dirname(__file__)
handlePDF(fitz.open(os.path.join(folder, "test.pdf"))).save(os.path.join(folder, "output.pdf"))

image
image

How to reproduce the bug

bug-report.tar.gz

  1. Download bug-report.tar.gz, extract, and cd to bug-report.

  2. Create a virtual python environment with pymupdf 1.24.1 or 1.24.0 installed.

  3. Activate the virtual environment and run python test.py, you will see result as I reported above.

PyMuPDF version

1.24.1

Operating system

Linux

Python version

3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix developedrelease schedule to be determinedupstream bugbug outside this package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions