PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

There is a bug in the add_redact_annot() function

Open lancer92-rep opened this issue 1 year ago • 3 comments

Description of the bug

When the PDF created after deleting text by applying the add_redact_annot() function is opened in a web browser, the shapes are not displayed correctly.

How to reproduce the bug

    doc = pymupdf.open(pdf_file)
    for page in doc:
        blks = page.get_text("blocks", sort=True, flags=pymupdf.TEXTFLAGS_DICT)
        for blk in blks:
            rect = pymupdf.Rect(blk[0], blk[1], blk[2], blk[3])
            page.add_redact_annot(rect)
        page.apply_redactions(images=0, graphics=0)
    file_name, file_extension = os.path.splitext(pdf_file)
    new_file = f"{file_name}_o{file_extension}"
    doc.subset_fonts()
    doc.ez_save(new_file, garbage=4)
    doc.close()

Some of the information in the shapes is clustered at the bottom left of the page. image If you repair it using some repair tools, the file will display normally in the browser.

The original file is as follows. sample_A.pdf

This is the file before applying add_redact_annot(). sample_A_red.pdf

The final file is as follows. sample_A_o.pdf

PyMuPDF version

1.24.7

Operating system

Windows

Python version

3.10

lancer92-rep avatar Jul 01 '24 10:07 lancer92-rep

Duplicate of #3630.

JorjMcKie avatar Jul 01 '24 10:07 JorjMcKie

The above bug still appears in pymupdf 1.24.8. I think it's a different bug than Issue 3630.

lancer92-rep avatar Jul 24 '24 14:07 lancer92-rep

The new PyMuPDF version 1.24.8 still does not contain the required MuPDF fix.

JorjMcKie avatar Jul 24 '24 15:07 JorjMcKie

Fixed in an earlier release already (pre 1.24.11).

JorjMcKie avatar Oct 05 '24 20:10 JorjMcKie