From 9f4f3926655c80b8e4a16470164057ef89135597 Mon Sep 17 00:00:00 2001 From: Josh Henderson Date: Fri, 9 Dec 2022 21:59:57 +1100 Subject: [PATCH 1/2] properly scaling annotations --- PyPDF2/_page.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PyPDF2/_page.py b/PyPDF2/_page.py index d75d053ae..8d680cfba 100644 --- a/PyPDF2/_page.py +++ b/PyPDF2/_page.py @@ -58,6 +58,7 @@ from .constants import ImageAttributes as IA from .constants import PageAttributes as PG from .constants import Ressources as RES +from .constants import AnnotationDictionaryAttributes as ADA from .errors import PageSizeNotDefinedError from .filters import _xobj_to_image from .generic import ( @@ -1057,6 +1058,19 @@ def scale(self, sx: float, sy: float) -> None: self.bleedbox = self.bleedbox.scale(sx, sy) self.trimbox = self.trimbox.scale(sx, sy) self.mediabox = self.mediabox.scale(sx, sy) + + if PG.ANNOTS in self: + annotations = self[PG.ANNOTS] + for annotation in annotations: + annotation_obj = annotation.get_object() + if ADA.Rect in annotation_obj: + rectangle = annotation_obj[ADA.Rect] + if isinstance(rectangle, ArrayObject): + rectangle[0] = FloatObject(float(rectangle[0]) * sx) + rectangle[1] = FloatObject(float(rectangle[1]) * sy) + rectangle[2] = FloatObject(float(rectangle[2]) * sx) + rectangle[3] = FloatObject(float(rectangle[3]) * sy) + if PG.VP in self: viewport = self[PG.VP] if isinstance(viewport, ArrayObject): From 2a060d9e8167dd4f8004ae2a423120b5177b751c Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 10 Dec 2022 10:01:59 +0100 Subject: [PATCH 2/2] Update PyPDF2/_page.py --- PyPDF2/_page.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/PyPDF2/_page.py b/PyPDF2/_page.py index 7477bb93a..52863407c 100644 --- a/PyPDF2/_page.py +++ b/PyPDF2/_page.py @@ -1061,15 +1061,16 @@ def scale(self, sx: float, sy: float) -> None: if PG.ANNOTS in self: annotations = self[PG.ANNOTS] - for annotation in annotations: - annotation_obj = annotation.get_object() - if ADA.Rect in annotation_obj: - rectangle = annotation_obj[ADA.Rect] - if isinstance(rectangle, ArrayObject): - rectangle[0] = FloatObject(float(rectangle[0]) * sx) - rectangle[1] = FloatObject(float(rectangle[1]) * sy) - rectangle[2] = FloatObject(float(rectangle[2]) * sx) - rectangle[3] = FloatObject(float(rectangle[3]) * sy) + if isinstance(annotations, ArrayObject): + for annotation in annotations: + annotation_obj = annotation.get_object() + if ADA.Rect in annotation_obj: + rectangle = annotation_obj[ADA.Rect] + if isinstance(rectangle, ArrayObject): + rectangle[0] = FloatObject(float(rectangle[0]) * sx) + rectangle[1] = FloatObject(float(rectangle[1]) * sy) + rectangle[2] = FloatObject(float(rectangle[2]) * sx) + rectangle[3] = FloatObject(float(rectangle[3]) * sy) if PG.VP in self: viewport = self[PG.VP]