pdftopdf QPDF: Ghostscript transparency performance optimization#147
Open
ValdikSS wants to merge 2 commits into
Open
pdftopdf QPDF: Ghostscript transparency performance optimization#147ValdikSS wants to merge 2 commits into
ValdikSS wants to merge 2 commits into
Conversation
…age. To adapt the PDF for printing, pdftopdf wraps each page of the PDF file into XObject, moving all the page properties inside it, and defining new MediaBox / Matrix for the Page. However moving Transparency Group into wrapping XObject prevents Ghostscript from detecting "fake transparency"—situation when the transparency is defined but not really used or needed. Transparency processing significantly slows down Ghostscript. Keep Transparency Group in Page declaration, do not move it into XObject. Fixes: OpenPrinting/cups-filters#569 Link: https://bugs.ghostscript.com/show_bug.cgi?id=707523 Link: OpenPrinting/cups-filters#569
If we're printing multiple PDF pages on a single physical page, and they have different Transparency Group definitions (with different color spaces or other parameters), fall back to the original code where we do not promote Transparency Group into Page declaration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Forward-port of the same changes for cups-filters 1.x: OpenPrinting/cups-filters#669
Original issue: OpenPrinting/cups-filters#569
When pdftopdf moves all the Page option definitions into wrapping XObject, moving Transparency Group into XObject declaration prevents Ghostscript from detecting fake transparency (when the transparency is defined but not used), which slows the document rasterization.
Keep Transparency Group in Page declaration unless two or more pages with different transparency options are printed:
number-up: TG is in Pagenumber-up=X, same TGs in each page: TG is in Pagenumber-up=X, different TGs: fall back to TG in XObjectsSee OpenPrinting/cups-filters#569 (comment) and https://bugs.ghostscript.com/show_bug.cgi?id=707523#c6 for more information.
Test case
price.pdf file has
/S /Transparencygroup defined for each page, pages 1-3 have fake transparency with only text, and only page 4 has a picture.I've tested the patch accross my small collection of PDF files, and special transparency testing files (here and also this one), and all of them produce identical byte-to-byte rasterization result with and without the patch.
However I'm not versed in PDF at all, that's why think of this MR as a draft proposal, it need some additional validation that this approach is correct in all cases.