Reputation: 273
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
Upvotes: 5
Views: 4220
Reputation: 18851
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.
Upvotes: 5