Skip to content

Commit

Permalink
PDFBOX-3690: use cropbox instead of mediabox sizes / compensate for c…
Browse files Browse the repository at this point in the history
…ropbox origins when rotating

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922720 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 28, 2024
1 parent 17519ff commit 88db8be
Showing 1 changed file with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,27 @@ private void stripPage(int page) throws IOException
// page may be rotated
rotateAT = new AffineTransform();
int rotation = pdPage.getRotation();
if (rotation != 0)
switch (rotation)
{
PDRectangle mediaBox = pdPage.getMediaBox();
switch (rotation)
{
case 90:
rotateAT.translate(mediaBox.getHeight(), 0);
break;
case 270:
rotateAT.translate(0, mediaBox.getWidth());
break;
case 180:
rotateAT.translate(mediaBox.getWidth(), mediaBox.getHeight());
break;
default:
break;
}
rotateAT.rotate(Math.toRadians(rotation));
case 0:
transAT = AffineTransform.getTranslateInstance(-cropBox.getLowerLeftX(), cropBox.getLowerLeftY());
break;
case 90:
rotateAT.translate(cropBox.getHeight(), 0);
transAT = AffineTransform.getTranslateInstance(-cropBox.getLowerLeftY(), -cropBox.getLowerLeftX());
break;
case 270:
rotateAT.translate(0, cropBox.getWidth());
transAT = AffineTransform.getTranslateInstance(cropBox.getLowerLeftY(), cropBox.getLowerLeftX());
break;
case 180:
rotateAT.translate(cropBox.getWidth(), cropBox.getHeight());
transAT = AffineTransform.getTranslateInstance(cropBox.getLowerLeftX(), -cropBox.getLowerLeftY());
break;
default:
break;
}

// cropbox
transAT = AffineTransform.getTranslateInstance(-cropBox.getLowerLeftX(), cropBox.getLowerLeftY());
rotateAT.rotate(Math.toRadians(rotation));

g2d = image.createGraphics();
g2d.setStroke(new BasicStroke(0.1f));
Expand Down

0 comments on commit 88db8be

Please sign in to comment.