I am quit new to using PDFBox. What I need is to add an image with rotation to an exiting PDF! I know how to add the image, but my problem is how to rotate the image! I've seen somethign about AffineTransform and Matrix but I have no idea what is that and how it works!
I'd really appreciate passing some sample code, and thank you in advance!
Best Regards
It helps to look at the source of the "simple" image display method:
public void drawXObject(PDXObject xobject, float x, float y, float width, float height)
{
AffineTransform transform = new AffineTransform(width, 0, 0, height, x, y);
drawXObject(xobject, transform);
}
so this is what you do to display an image at (200,200) with a rotation of 45°:
AffineTransform at = new AffineTransform(ximage.getWidth(), 0, 0, ximage.getHeight(), 200, 200);
at.rotate(Math.toRadians(45));
contentStream.drawXObject(ximage, at);
Re: AffineTransform: this is a subtopic of geometry. To get an introduction, read the java description here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With