Skip to content

Commit

Permalink
BUG: Fix error adding transformation to page without /Contents
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peveler <[email protected]>
  • Loading branch information
MasterOdin committed May 27, 2022
1 parent b387b06 commit 937e551
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PyPDF2/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ def add_transformation(
if content is not None:
content = PageObject._add_transformation_matrix(content, self.pdf, ctm)
content = PageObject._push_pop_gs(content, self.pdf)
self[NameObject(PG.CONTENTS)] = content
# if expanding the page to fit a new page, calculate the new media box size
if expand:
corners = [
Expand Down Expand Up @@ -929,7 +930,6 @@ def add_transformation(

self.mediabox.lower_left = lowerleft
self.mediabox.upper_right = upperright
self[NameObject(PG.CONTENTS)] = content

def addTransformation(self, ctm: CompressedTransformationMatrix) -> None:
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,8 @@ def test_page_scale():

assert op.scale(sx=2).ctm == (2, 0, 0, 2, 0, 0)
assert op.scale(sy=3).ctm == (3, 0, 0, 3, 0, 0)


def test_add_transformation_on_page_without_contents():
page = PageObject()
page.add_transformation(Transformation())

0 comments on commit 937e551

Please sign in to comment.