title: PDFBox - obtain bounding box of rotated image
body: <p>I'm working with PDFBox and trying to rotate an image and have it position correctly on the screen. The design editor I'm using outputs the following information about images that may be useful.</p>
  
  <p>Image bounding box top-left coords (I'm using the bottom left coords to better suit PDFBox coord space.)</p>
  
  <p>Image rotation in degrees</p>
  
  <p>Image width &amp; height</p>
  
  <p>The translation appears to be off.</p>
  
  <pre><code>// Rotation
  AffineTransform rotation = new AffineTransform();
  rotation.rotate(Math.toRadians(360 - element.getAngle()),
      element.getLeft() + scaledWidth/2,
      adjustedYPos + scaledHeight/2);
      stream.transform(new Matrix(rotation));
  
  // Position &amp; scale
  AffineTransform mat = new AffineTransform(scaledWidth,
          0,
          0,
          scaledHeight,
          element.getLeft(),
          adjustedYPos);
  
  // Draw the final image
  stream.drawImage(pdfImage, new Matrix(mat));
  </code></pre>
  
  <p>Rotations are based on the center of the image as an anchor point.</p>