Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Scale PDF annotations #1479

Merged
merged 3 commits into from Dec 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 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,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)
MartinThoma marked this conversation as resolved.
Show resolved Hide resolved

if PG.VP in self:
viewport = self[PG.VP]
if isinstance(viewport, ArrayObject):
Expand Down