Skip to content

Commit

Permalink
BUG: Page.scale now also scales the cropbox
Browse files Browse the repository at this point in the history
Closes #272

Co-authored-by: Brian Painter <[email protected]>
  • Loading branch information
MartinThoma and BrianPainter committed Jul 6, 2022
1 parent a345690 commit c6df14e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 5 additions & 8 deletions PyPDF2/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,18 +897,15 @@ 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.
:param float sx: The scaling factor on horizontal axis.
:param float sy: The scaling factor on vertical axis.
"""
self.add_transformation((sx, 0, 0, sy, 0, 0))
self.mediabox = RectangleObject(
(
float(self.mediabox.left) * sx,
float(self.mediabox.bottom) * sy,
float(self.mediabox.right) * sx,
float(self.mediabox.top) * sy,
)
)
self.mediabox = self.mediabox.scale(sx, sy)
self.cropbox = self.cropbox.scale(sx, sy)
if PG.VP in self:
viewport = self[PG.VP]
if isinstance(viewport, ArrayObject):
Expand Down
10 changes: 10 additions & 0 deletions PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,16 @@ def _ensure_is_number(self, value: Any) -> Union[FloatObject, NumberObject]:
value = FloatObject(value)
return value

def scale(self, sx: float, sy: float) -> "RectangleObject":
return RectangleObject(
(
float(self.left) * sx,
float(self.bottom) * sy,
float(self.right) * sx,
float(self.top) * sy,
)
)

def ensureIsNumber(
self, value: Any
) -> Union[FloatObject, NumberObject]: # pragma: no cover
Expand Down

0 comments on commit c6df14e

Please sign in to comment.