ENH: Background argument and auto-rotation when merging pages#410
ENH: Background argument and auto-rotation when merging pages#410hvbtup wants to merge 5 commits intopy-pdf:mainfrom
Conversation
The mergePage methods now support an additional argument background. If this is true, the content of the second page appears *under* the content of the first page instead of on top of it.
Added a new method mergeAutoRotatedPage to support auto-rotating the second page: If the first page is landscape and the second page is portrait, the second page will be rotated clockwise by 90°. If the first page is portrait and the second page is landscape, the second page will be rotatet counter-clockwise by 90°. The rotation center is rot_center_x = rot_center_y = min(page2.width, page2.height) / 2.
|
Thank you for your contribution ❤️ Since you've opened this PR, PyPDF2 was dormant for a long time. I'm sorry that you didn't receive feedback. With the new interface for adding transformations to a single page / merging, I think this is no longer necessary. I'll close it for this reason. Please let me know if you still would like the new method to be in PyPDF2. |
|
@MartinThoma Please take another close look at the PR: The current API doesn't support creating true watermarks, because - as the doc say: The parameter page's content stream will be added to the end of this page's content stream, meaning that it will be drawn after, or "on top" of this page. So, the current API only supports kind of stamping, but not watermarking. |
|
Thank you for the clarification! Now I've got it :-) |
|
I just gave it a second thought: # watermark
image_page.merge_page(content_page)
# stamp
content_page.merge_page(image_page)@hvbtup Wouldn't that be possible? Is there a drawback of doing it like this? |
I really doubt that would work. I don't know how PyPDF2 works internally, but I assume that there is a huge difference between a PDF (and the correponding pages) opened for reading and those opened for writing. |
These changes extend the merging capabilities:
Together, thsi allows easy adding of a watermark PDF page with a content like "Top Secret" to a source PDF independent of the source PDF's orientation (the text on the watermark should go diagonal from bottom left to top right)