-
Notifications
You must be signed in to change notification settings - Fork 510
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
save(garbage=3) breaks get_pixmap() with side effect #2596
Comments
This is sad indeed. Please do provide some reproducing file, or otherwise we won't be able to accept the report. |
Other missing information pieces pertain to you platform and PyMuPDF version. |
Thanks for the quick response. I updated the description. I will have to check if there is a way to provide you with the documents - this might take some time. |
You can use my private e-mail address. This way there will be no public visibility. |
I just received the example file - thanks a lot. I did a few tests and found that this probably is no bug. Instead, a few precautions should be taken to ensure properly created pixmaps in this situation.
So wrapping up, the following sequence of instructions should prevent the problem: pix1 = page.get_pixmap()
doc.save(... with garbage>0 or other changes ...)
# the following instructions will make sure that
# the pixmap is made from updated data.
fitz.TOOLS.store_shrink(100) # clears the internal cache
page = doc.reload_page(page) # reload the page preserving dependent objects
pix2 = page.get_pixmap() So as a general rule, you should
|
Thank you for your work! But the mixing up of the images in the page still seems like a bug to me. If I understood it correctly the problems are the cached images that are renumbered during saving and falsely referenced after that which leads to the switched appearances. Updating the cached images with the new indices during saving would fix the issue, wouldn't it? |
May well be. But that is not what a cache is for: its sense in life is to save work, not the opposite. |
When continuing to use a page object after the PDF has been saved with garbage options may change the MuPDF cache such that e.g. rendering the page after the save will produce wrong appearance or even garbled appearance. The user needs to reload the page (page = doc.reload(page)) before using it further, especially for rendering. The reload method now always empties the cache.
The underlying fz_page was being kept alive so reload_page()'s call of fz_load_page() was returning it from the document's internal list of pages instead of regenerating it.
The underlying fz_page was being kept alive so reload_page()'s call of fz_load_page() was returning it from the document's internal list of pages instead of regenerating it.
Fixed in 1.23.5. |
Problem
After saving the fitz.Document with
pdf.save("filename.pdf", garbage=3)
the embedded images of the document I can see in the pixmap of the pages are mixed up:pixmap = pdf[0].get_pixmap()
.fitz.Document.save(garbage=3)
andfitz.Document.write(garbage=3)
appear to have side effects that change the document in place.When I set
garbage
to 2 it works as expected.Observation
Checked checkboxes become unchecked boxes and the other way around, some checkboxes become logos etc..
Code Example
Sadly I can't provide the affected internal documents.
Version
Installed with
pip install PyMuPdf
I also tested it on 1.22.5 on macOS with the same result.
The text was updated successfully, but these errors were encountered: