-
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
Support for merging a page in the background (watermark) #307
Comments
This is the patch for PyPDF2/pdf.py. |
I have not tested your code, but I think your example is probably too simple. The typical use case is: Since your example code for creating a watermark modifies the image page in-place, I don't think it will work for this use case. |
What do you think would go wrong? (As an important side-note: You need to copy the watermark or re-load it every time, of course) |
Would that be cumbersome and counter-intuitive? I think the approach to specify wether the "image page" should go above or below the existing content with an optional argument is much more user-friendly. BTW The well-known Java iText PDF library uses the words "OverContent" and "UnderContent" for this, but people don't understand that (https://stackoverflow.com/questions/66029258/difference-between-getundercontent-and-getovercontent-of-itext). IMHO the wording "background" for a boolean argument is more clear, but I'm biased of course. |
An image says more than 1000 words: https://pypdf2.readthedocs.io/en/latest/user/add-watermark.html 😄 I want to keep the public interface of PyPDF2 small and hence I hesitate to add such features which are easy to do on the users side. But I get your point that users might not understand that they need to copy the page. I think I'll wait and see how many people open stackoverflow questions / issues here. If this is really an issue, adding this feature is pretty easy. |
Oh, and I should adjust the docs to make a copy so that people who simply copy-and-paste don't fall into this trap |
It's good that you show a complete example in add-watermark.md. Of course parsing the stamp file inside the loop with
will cost some performance. I hope this isnt' really an issue. If it turns out to be an issue, one could still modify PyPDF2 to use my approach instead. |
I completely agree that this is not ideal. I actually thought it would be simpler - using Turns out, that |
I propose adding an optional argument background=False to the various merge...Page methods.
All these methods finally go into _mergePage. There, the following little change should to the trick:
The text was updated successfully, but these errors were encountered: