From 2cb9f42507a9ec7375958606c75791e202274e49 Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Mon, 16 May 2022 11:53:00 +0200 Subject: [PATCH 1/4] BUG : Fix merge of a cropped page tracked in #636 thee smaller box between cropBox is and trimBox(== mediaBox by default) is used --- PyPDF2/_page.py | 13 +++++++++---- tests/test_page.py | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/PyPDF2/_page.py b/PyPDF2/_page.py index 01b45d8a1..c65048ef5 100644 --- a/PyPDF2/_page.py +++ b/PyPDF2/_page.py @@ -352,16 +352,21 @@ def _mergePage( page2content = page2.getContents() if page2content is not None: page2content = ContentStream(page2content, self.pdf) + if(page2.cropBox.getWidth() Date: Mon, 23 May 2022 22:43:44 +0200 Subject: [PATCH 2/4] Apply suggestions from code review --- PyPDF2/_page.py | 10 ++++++---- tests/test_page.py | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/PyPDF2/_page.py b/PyPDF2/_page.py index 7e4eda5d1..b8b9947bd 100644 --- a/PyPDF2/_page.py +++ b/PyPDF2/_page.py @@ -539,11 +539,13 @@ def _merge_page( page2content = page2.getContents() if page2content is not None: page2content = ContentStream(page2content, self.pdf) - if(page2.cropBox.getWidth() Date: Mon, 23 May 2022 22:45:57 +0200 Subject: [PATCH 3/4] Apply suggestions from code review --- tests/test_page.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_page.py b/tests/test_page.py index 1dce2f7c5..1adbdf253 100644 --- a/tests/test_page.py +++ b/tests/test_page.py @@ -179,8 +179,8 @@ def test_page_rotation_non90(): def test_page_merge_cropped(): p = PdfReader(os.path.join(RESOURCE_ROOT, "issue-604.pdf")) - a = deepcopy(p.page[1]) # crossed to ease test reading - b = deepcopy(p.page[2]) + a = deepcopy(p.pages[1]) # crossed to ease test reading + b = deepcopy(p.pages[2]) a.cropbox = RectangleObject([100, 100, 300, 200]) w = PdfWriter() w.add_page(a) From bc6f8eddb1c368b2bc84fa304a11f4adb1039fa2 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Tue, 28 Jun 2022 19:06:19 +0200 Subject: [PATCH 4/4] Update tests/test_page.py --- tests/test_page.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_page.py b/tests/test_page.py index 3baa27e59..c64081715 100644 --- a/tests/test_page.py +++ b/tests/test_page.py @@ -195,6 +195,7 @@ def test_page_rotation_non90(): page.rotate(91) assert exc.value.args[0] == "Rotation angle must be a multiple of 90" + def test_page_merge_cropped(): p = PdfReader(os.path.join(RESOURCE_ROOT, "issue-604.pdf")) a = deepcopy(p.pages[1]) # crossed to ease test reading