Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result for apply_redactions() #4079

Open
slevin1994 opened this issue Nov 22, 2024 · 2 comments
Open

Unexpected result for apply_redactions() #4079

slevin1994 opened this issue Nov 22, 2024 · 2 comments
Labels
upstream bug bug outside this package

Comments

@slevin1994
Copy link

slevin1994 commented Nov 22, 2024

Description of the bug

My pymupdf version is 1.24.14.
I tried invoke add_redact_annot(rect) and apply_redactions(images=0) to remove some words from original pdf file. The locations are shown as below:
image

However words remanins in these rect areas. Meanwhile some other words were removed unexpectly. The result is shown
as below:
image

I also attached the files mentioned above, along with the rect positions.

original pdf file: redactions_error_sample.pdf

result file after add_redact_annot(rect):
before_apply_redactions.pdf

result after apply_redactions(images=0):
after_apply_redactions.pdf

rect areas: [{"rect":[164,213,282,227]},{"rect":[282,213,397,233]},{"rect":[434,209,525,243]},{"rect":[169,228,231,243]},{"rect":[377,592,440,607]},{"rect":[373,611,444,626]}]

How to reproduce the bug

doc = fitz.open("redactions_error_sample.pdf")
page = doc.load_page(0)
for rect in rects:
  page.add_redact_annot(rect)
doc.save("before_apply_redactions.pdf")
page.apply_redactions(images=0)
doc.save("after_apply_redactions.pdf")

PyMuPDF version

1.24.14

Operating system

MacOS

Python version

3.9

@jamie-lemon
Copy link
Collaborator

I thought your rects array was dubious. This worked for me:

import pymupdf

doc = pymupdf.open("redactions_error_sample.pdf")
page = doc.load_page(0)

rects = [[164,213,282,227],[282,213,397,233],[434,209,525,243],[169,228,231,243],[377,592,440,607],[373,611,444,626]]

for rect in rects:
  page.add_redact_annot(rect, fill=(1,0,0))

# Apply the redactions to the current page, but ignore images
page.apply_redactions(images=0)

doc.save("after_apply_redactions.pdf")

doc.close()

@JorjMcKie
Copy link
Collaborator

This is an upstream error. The corresponding MuPDF bug rreport: https://bugs.ghostscript.com/show_bug.cgi?id=708157.

@JorjMcKie JorjMcKie added the upstream bug bug outside this package label Nov 23, 2024
julian-smith-artifex-com added a commit that referenced this issue Nov 27, 2024
Test currently expects the current broken behaviour.
julian-smith-artifex-com added a commit that referenced this issue Nov 27, 2024
Test currently expects the current broken behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream bug bug outside this package
Projects
None yet
Development

No branches or pull requests

3 participants