The Transformation Class
- class PyPDF2.Transformation(ctm: Tuple[float, float, float, float, float, float] = (1, 0, 0, 1, 0, 0))[source]
Bases:
object
Specify a 2D transformation.
The transformation between two coordinate systems is represented by a 3-by-3 transformation matrix written as follows:
a b 0 c d 0 e f 1
Because a transformation matrix has only six elements that can be changed, it is usually specified in PDF as the six-element array [ a b c d e f ].
Coordinate transformations are expressed as matrix multiplications:
a b 0 [ x′ y′ 1 ] = [ x y 1 ] × c d 0 e f 1
>>> from PyPDF2 import Transformation >>> op = Transformation().scale(sx=2, sy=3).translate(tx=10, ty=20) >>> page.add_transformation(op)
- static compress(matrix: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]]) Tuple[float, float, float, float, float, float] [source]
- property matrix: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]]
- rotate(rotation: float) PyPDF2._page.Transformation [source]
- scale(sx: Optional[float] = None, sy: Optional[float] = None) PyPDF2._page.Transformation [source]
- translate(tx: float = 0, ty: float = 0) PyPDF2._page.Transformation [source]