From 5ece2ae2ead33ac8407edd26786613ee3990ee85 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Thu, 24 Apr 2025 21:48:56 +0100 Subject: [PATCH 1/2] MAINT: Tweak class PageObject Remove a redundant comment and modify some other comments. Reorder page boundaries to familiar order. --- pypdf/_page.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pypdf/_page.py b/pypdf/_page.py index f7e18ff30..7a7fd8ea7 100644 --- a/pypdf/_page.py +++ b/pypdf/_page.py @@ -508,7 +508,6 @@ def __init__( DictionaryObject.__init__(self) self.pdf = pdf self.inline_images: Optional[Dict[str, ImageFile]] = None - # below Union for mypy but actually Optional[List[str]] self.indirect_reference = indirect_reference if not is_null_or_none(indirect_reference): assert indirect_reference is not None, "mypy" @@ -1116,11 +1115,11 @@ def merge_page( """ Merge the content streams of two pages into one. - Resource references - (i.e. fonts) are maintained from both pages. The mediabox/cropbox/etc - of this page are not altered. 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. + Resource references (e.g. fonts) are maintained from both pages. + The mediabox, cropbox, etc of this page are not altered. + 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. Args: page2: The page to be merged into this one. Should be @@ -1569,19 +1568,16 @@ def add_transformation( for i in range(0, 8, 2) ] - lowerleft = (min(new_x), min(new_y)) - upperright = (max(new_x), max(new_y)) - - self.mediabox.lower_left = lowerleft - self.mediabox.upper_right = upperright + self.mediabox.lower_left = (min(new_x), min(new_y)) + self.mediabox.upper_right = (max(new_x), max(new_y)) def scale(self, sx: float, sy: float) -> None: """ Scale a page by the given factors by applying a transformation matrix to its content and updating the page size. - This updates the mediabox, the cropbox, and the contents - of the page. + This updates the various page boundaries (mediabox, cropbox, etc) + and the contents of the page. Args: sx: The scaling factor on horizontal axis. @@ -1589,11 +1585,11 @@ def scale(self, sx: float, sy: float) -> None: """ self.add_transformation((sx, 0, 0, sy, 0, 0)) + self.mediabox = self.mediabox.scale(sx, sy) self.cropbox = self.cropbox.scale(sx, sy) - self.artbox = self.artbox.scale(sx, sy) self.bleedbox = self.bleedbox.scale(sx, sy) self.trimbox = self.trimbox.scale(sx, sy) - self.mediabox = self.mediabox.scale(sx, sy) + self.artbox = self.artbox.scale(sx, sy) if PG.ANNOTS in self: annotations = self[PG.ANNOTS] From 91a0dd8f4d2b4b093ed4ab354c473113baea23bd Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Mon, 28 Apr 2025 15:26:30 +0200 Subject: [PATCH 2/2] Update pypdf/_page.py --- pypdf/_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypdf/_page.py b/pypdf/_page.py index 7a7fd8ea7..aed714fbe 100644 --- a/pypdf/_page.py +++ b/pypdf/_page.py @@ -1576,7 +1576,7 @@ def scale(self, sx: float, sy: float) -> None: Scale a page by the given factors by applying a transformation matrix to its content and updating the page size. - This updates the various page boundaries (mediabox, cropbox, etc) + This updates the various page boundaries (mediabox, cropbox, etc.) and the contents of the page. Args: