-
Notifications
You must be signed in to change notification settings - Fork 529
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
apply_redactions causes part of the page content to be hidden / transparent #3751
Comments
I faced the same problem. There is also an interesting thing. If you open redacted PDF via Chrome or LibreOffice it will look as expected. But the issue is reproducible at least with Mac Preview and react-pdf-viewer lib. |
As always: please provide an example PDF! There is no way to otherwise deal with this post. |
I've just tested and it works on older version (up to pymupdf-1.23.26). Perhaps easier to compare the commits since a868c0a until HEAD. |
@JorjMcKie Please, open the redacted file with the Preview app, it will look like this The code for redaction looks like this:
|
@JorjMcKie |
@Kyrylo-Hrytsenko Thanks, I did. I executed the script and found no problem at all using v1.24.9. I modified the script somewhat so redaction rectangles are visible and erased areas are not filled: import pymupdf
print(pymupdf.version)
pdfIn = pymupdf.open("original.pdf")
page = pdfIn[0]
rects = (
[0, 0, 100, 100],
[100, 100, 200, 200],
[200, 200, 300, 300],
[300, 300, 400, 400],
)
for r in rects:
page.draw_rect(r, color=(1, 0, 0))
page.add_redact_annot(r)
page.apply_redactions()
pdfIn.ez_save("output.pdf") Gives this correct result: |
@JorjMcKie Notes:
Does the output.pdf look normal when you open it in the 'Preview' application? |
I do not use or have Preview. |
Can confirm also see this problem in Preview. However it is fine when I open in Adobe Acrobat. To me this feels like a Preview rendering bug. I would submit a bug to Apple if that is possible! |
@jamie-lemon absolutely correct! I was about to write a similar comment. |
@jamie-lemon @JorjMcKie
|
@JorjMcKie @jamie-lemon |
This is a strange bug - I thought it might be related to the content on page 1, but if I simplify things, target the 2nd page with an area redaction with:
I also noticed that it doesn't matter how big the area redaction, I could do this:
And achieve the same resulting problem with the left hand side of the page. I could also put that rect anywhere on the page - it didn't have to be in the top left. Testing with other documents, redacting and viewing in Preview I don't find this issue at all, so I think there must be something very specific to this document which will need further research. |
Totally agree. Only a small number of my documents have this bug. I didn't even plan to write to you but then noticed that this is happening not only to me and the bug was already created, so I added my example as well. |
@Kyrylo-Hrytsenko Much appreciated! |
So it seems if the PDF is made in Preview then this might have something to do with the problem. |
The issue I am encountering is that if apply_redactions is used, the vector graphics on the page all move to the bottom left corner in Preview, Safari, UPDF, and PDF Expert, whereas they display correctly in Chrome, Adobe Acrobat Reader, and WPS. Here is the code: import fitz
doc = fitz.open('origin.pdf')
page = doc.load_page(0)
page.add_redact_annot((0, 0, 0 ,0), fill=False)
page.apply_redactions()
doc.ez_save('apply_redaction.pdf')
doc.close() origin.pdf The |
The PDF generated with PyMuPDF version 1.23.26 displays the vector graphics correctly in Preview (although the image in the top right corner is partially missing). However, starting from version 1.24.0, there is a bug where the vector graphics are moved to the bottom left corner. |
It seems that primarily Mac-based tools have problems with redacted PDFs that have been created with Preview. When creating and applying annotations using PyMuPDF 1.24.9 with MuPDF 1.25.0 I do no longer see the error using the Firefox browser - which does behave awkwardly as all those Mac apps. I am attaching the produced output.pdf inviting Mac users to access it with their Preview on Mac: |
It seems that this bug still exists in Mac Preview. |
@yuhuang-cst thanks for the feedback anyway |
Can also confirm that the bug doesn't exist in PyMuPDF version 1.23.9 |
I have submitted a problem report in MuPDF's system here:https://bugs.ghostscript.com/show_bug.cgi?id=707966 |
Report the same issue。 |
Apparent MuPDF master branch has a fix, so PyMuPDF itself will be fixed when we make a release with MuPDF-1.25.0. However i don't currently know when MuPDF_1.25.0 will be released. |
@julian-smith-artifex-com @JorjMcKie Let's release soon to hopefully fix this one! Related I think: #4029 |
Description of the bug
I'm adding a redaction region to a part of the PDF, but after calling apply_redactions(), one side of the entire page goes missing (opened in macOS Preview app or Safari).
Further inspection reveals that the text is not missing, as it is selectable and can be copied out properly. It is either the text has been masked / hidden, but I could not find out how to check further (sorry, my limited knowledge on PDF structure).
The media, crop, art, bleed, trim boxes all looks fine before and after the redactions. In fact, I'm trying to check if there's other paths, objects that may be causing it but there's nothing.
Note that I'm not able to share the actual PDF but it was generated from Puppeteer / Chromium (PDF ver 1.7).
Thanks in advance for looking into this.
How to reproduce the bug
(0,0,1,1)
and callapply_redactions()
PyMuPDF version
1.24.9
Operating system
MacOS
Python version
3.9
The text was updated successfully, but these errors were encountered: