5

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

user256872
  • 273
  • 2
  • 5
  • 10

1 Answers1

5

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.

Dani
  • 3,744
  • 4
  • 27
  • 35
Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97