When you set a rotation using the setRotationDegrees()
method, the image is rotated using the lower-left corner of the image as its rotation point. If you want another rotation point, you'll need to work with low-level functionality to change the CTM. See the different addImage()
methods in the PdfContentByte
class for more info:
addImage(Image image, AffineTransform transform)
adds an Image
with the given transformation defined using the com.itextpdf.awt.geom.AffineTransform
class.
addImage(Image image, float a, float b, float c, float d, float e, float f)
adds an Image
using a CTM that is defined by the values a
, b
, c
, d
, e
and f
which are elements of a 3 by 3 matrix. E.g. e
and f
define the translation.
For more detailed info on the coordinate system and the transformation matrices, please read The ABC of PDF with iText. The book isn't finished yet, but it's free and the part you need is already there.
If you want to define the rotation yourself, you need to understand two very important concepts in PDF:
- The origin of the coordinate system is defined by the MediaBox. If the mediabox is defined like this
[0 0 595 842]
(which is an A4 page) and there is no cropbox, then the origin of the coordinate system will be the lower-left corner of your page. The upper-right corner will have the coordinate (x = 595; y = 842).
- In PDF, you don't rotate objects. Instead you rotate the coordinate system. When you add an object to a rotated coordinate system, it looks as if the objects are rotated.
All of this is explained in ISO-32000-1 and in the ABC book I started writing.