Skip to content

Commit

Permalink
BUG: Scale PDF annotations (#1479)
Browse files Browse the repository at this point in the history
PDF annotations - for example hyperlinks and comments - were not properly scaled when using the scale function.

Fixes #1386
  • Loading branch information
joshhendo committed Dec 10, 2022
1 parent b1938aa commit 5fd96d0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions PyPDF2/_page.py
Expand Up @@ -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 (
Expand Down Expand Up @@ -1057,6 +1058,20 @@ 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]
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]
if isinstance(viewport, ArrayObject):
Expand Down

0 comments on commit 5fd96d0

Please sign in to comment.