-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Each page merge will add another graphics state isolation call #2219
Comments
@stefan6419846 |
It just bloats the PDF file unnecessarily when doing lots of page merges, for example by adding multiple overlays, without any real usage.
I do not understand this. Where am I talking about optimizing checks? Because I propose to cache the isolation state?
At least for the examples I have seen, we already have a string in |
Oups forgot some stash |
This issue was closed as no user stumbled over it so far. There was a PR solving it ( #2224 ), but we had concerns regarding special cases (split streams). For this reason, we decided to close the PR and the issue until somebody actually stumbles over it. |
Merging a page multiple times will isolate the graphics state multiple times instead of re-using the existing wrapping. This is unecessary and probably should be avoided by checking for an isolated graphics state before doing any wrapping. (This has been reported as a possible enhancement in #2203 as well, but extracted to a dedicated issue to allow easier tracking.)
Caching might be useful to avoid doing "expensive" checks each time.
See https://github.com/pymupdf/PyMuPDF/blob/1c2f1da3eb2541f1c8dbd50acb3a916939c99d3e/src/__init__.py#L9141-L9146 and https://github.com/pymupdf/PyMuPDF/blob/1c2f1da3eb2541f1c8dbd50acb3a916939c99d3e/src/__init__.py#L8864-L8876 for an examle implementation in PyMuPDF.
Environment
Which environment were you using when you encountered the problem?
Code + PDF
This is a minimal, complete example that shows the issue:
This happens for all PDF files.
Please note that the above example code is minimal, although using the same watermark twice is rather useless in production, but shows the issue anyway. Imagine you want to use two different backgrounds and/or overlays on the same page, which would trigger exactly the same.
Traceback
Suppose we start with
self._data
of the page beingq\n 841.680[...]0 Do\nQ\n\n \n
. Running the above example leads toself._data
beingq\nq\nq\n 841[...]ET\nQ\nQ\n\nQ\n
, thus we have isolated the graphics state three times, although once should be enough.The text was updated successfully, but these errors were encountered: