Skip to content

Commit

Permalink
BUG: Clip by trimBox when merging pages, which would otherwise be ign…
Browse files Browse the repository at this point in the history
…ored (#240)

Closes #163
  • Loading branch information
forrestv committed Apr 16, 2022
1 parent d5a5eea commit c138f21
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PyPDF2/pdf.py
Expand Up @@ -2380,6 +2380,10 @@ def _mergePage(self, page2, page2transformation=None, ctm=None, expand=False):

page2Content = page2.getContents()
if page2Content is not None:
page2Content = ContentStream(page2Content, self.pdf)
page2Content.operations.insert(0, [map(FloatObject, [page2.trimBox.getLowerLeft_x(), page2.trimBox.getLowerLeft_y(), page2.trimBox.getWidth(), page2.trimBox.getHeight()]), "re"])
page2Content.operations.insert(1, [[], "W"])
page2Content.operations.insert(2, [[], "n"])
if page2transformation is not None:
page2Content = page2transformation(page2Content)
page2Content = PageObject._contentStreamRename(
Expand Down

2 comments on commit c138f21

@kaneshiro1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am a total newb, but with this fix is there still a way to merge pdfs that contain bleed? Or, anything outside the trim box? I figure the ugly workaround will be to change the trim box size, but that seems to defeat the purpose of different media boxes. Is this addressed in version 2 and beyond?

@pubpub-zz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the content is out of the trimbox , you should not see it before merging.
However what you could do is set trimBox to a very area before merging.
I met this case when applying some transformation on page2. In such you can set expand to True before applying transformation.

Please sign in to comment.