BUG: Fix test_watermarking_reportlab_rendering()#2203
Conversation
|
I wonder if we could use this opportunity to consider that Edit: I did that in the 2nd commit of this PR, and it seems to work fine. |
f8e7fad to
c256b74
Compare
c256b74 to
a8ba231
Compare
What about to do the merge just work on the decode byte streams? to conversion to operations takes some times and we just need something like: no ? |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2203 +/- ##
==========================================
+ Coverage 94.37% 94.38% +0.01%
==========================================
Files 43 43
Lines 7588 7588
Branches 1496 1497 +1
==========================================
+ Hits 7161 7162 +1
+ Misses 263 262 -1
Partials 164 164
☔ View full report in Codecov by Sentry. |
Sorry, I don't quite understand your suggestion 😅 |
It is quite a draft. I will make a test and prepare a PR if performance is good 😉 |
Alright! 🙂 In the meantime, would you or @MartinThoma be OK to merge this PR? |
|
for me, this PR is completely valid and what I have in mind will not modify this PR. |
|
In PyMuPDF, double-wrapping will be prevented: https://github.com/pymupdf/PyMuPDF/blob/1c2f1da3eb2541f1c8dbd50acb3a916939c99d3e/src/__init__.py#L9141-L9146 (the Would this be a possible enhancement here as well? Otherwise, running pypdf on the same PDF page multiple times might generate lots of "useless" wrappers. |
|
Thank you for taking care of this @Lucas-C 🙏 I love that you're so actively contributing now 🎉 To me the PR looks good. @stefan6419846 left two interesting comments. I will take care of the docstring part, but the double-wrapping might be something interesting for another PR. |
I agree! 🙂 If I understand correctly, your suggestion @stefan6419846 would be to add a |
Yes, something like this.
It generally is good practice to already have an isolated graphics state for each page of the PDF file, so a "clean" PDF file would already have wrapped pages. pypdf will currently add another wrapping layer each time. An easy example to reproduce this is by adding two different watermarks/overlays/backgrounds for example: from pypdf import PdfReader, PdfWriter
watermark1 = PdfReader('watermark1.pdf').pages[0]
watermark2 = PdfReader('watermark2.pdf').pages[0]
writer = PdfWriter(clone_from='file.pdf')
for page in writer.pages:
page.merge_page(watermark1)
page.merge_page(watermark2)Suppose we start with |
|
@MartinThoma I've found a "regression" in the test the skipping decorator if ghostscript is not present is missing |
closes py-pdf#1910 address regression from py-pdf#2203
## What's new ### Bug Fixes (BUG) - PDF size increases because of too high float writing precision (#2213) by @pubpub-zz - Fix test_watermarking_reportlab_rendering() (#2203) by @LucasCimon ### Documentation (DOC) - Fix typos and add a paragraph to ViewerPreferences docs (#2199) by @marcstober - How to install pypi from any branch (#2209) by @pubpub-zz - Update copyright footer in docs (#2207) by @marcstober ### Developer Experience (DEV) - Let dependabot update Github Actions by @MartinThoma ### Maintenance (MAINT) - Update .pre-commit-config.yaml by @MartinThoma [Full Changelog](3.16.1...3.16.2)
This fixes the issue spotted in #2191
The solution was to re-introduce calls to
PageObject._push_pop_gs(),in
PageObject._merge_page&PageObject._merge_page_writer(),but to optimize
PageObject._push_pop_gs()by introducing aContentsStream.isolate_graphics_state()method.