Skip to content

ENH: Background argument and auto-rotation when merging pages#410

Closed
hvbtup wants to merge 5 commits intopy-pdf:mainfrom
hvbtup:master
Closed

ENH: Background argument and auto-rotation when merging pages#410
hvbtup wants to merge 5 commits intopy-pdf:mainfrom
hvbtup:master

Conversation

@hvbtup
Copy link
Copy Markdown

@hvbtup hvbtup commented Mar 22, 2018

These changes extend the merging capabilities:

  1. to auto-rotate the second page if first page and second page have different orientation.
  2. to add the second page's content to the background (behind) of the first page instead of on top of it.

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)

hvbtup added 4 commits March 21, 2018 20:07
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.
@MartinThoma MartinThoma added the PdfMerger The PdfMerger component is affected label Apr 6, 2022
@MartinThoma MartinThoma added the is-feature A feature request label Apr 16, 2022
@MartinThoma MartinThoma changed the title Support background argument and auto-rotation when merging pages. Background argument and auto-rotation when merging pages Apr 16, 2022
@MartinThoma MartinThoma added Feature and removed is-feature A feature request labels Apr 16, 2022
@MartinThoma MartinThoma changed the title Background argument and auto-rotation when merging pages ENH: Background argument and auto-rotation when merging pages Jun 25, 2022
@MartinThoma MartinThoma added needs-rebase This PR cannot be merged as the main branch is too different. You need to rebase or merge main. is-feature A feature request and removed Feature labels Jun 25, 2022
@MartinThoma
Copy link
Copy Markdown
Member

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 MartinThoma closed this Jul 5, 2022
@hvbtup
Copy link
Copy Markdown
Author

hvbtup commented Jul 6, 2022

@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.

@MartinThoma MartinThoma reopened this Jul 6, 2022
@MartinThoma
Copy link
Copy Markdown
Member

Thank you for the clarification! Now I've got it :-)

@MartinThoma
Copy link
Copy Markdown
Member

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?

@hvbtup
Copy link
Copy Markdown
Author

hvbtup commented Jul 6, 2022

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.

MartinThoma added a commit that referenced this pull request Jul 9, 2022
MartinThoma added a commit that referenced this pull request Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

is-feature A feature request needs-rebase This PR cannot be merged as the main branch is too different. You need to rebase or merge main. PdfMerger The PdfMerger component is affected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants