Skip to content

Commit 88db8be

Browse files
committed
PDFBOX-3690: use cropbox instead of mediabox sizes / compensate for cropbox origins when rotating
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922720 13f79535-47bb-0310-9956-ffa450edef68
1 parent 17519ff commit 88db8be

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,28 +206,27 @@ private void stripPage(int page) throws IOException
206206
// page may be rotated
207207
rotateAT = new AffineTransform();
208208
int rotation = pdPage.getRotation();
209-
if (rotation != 0)
209+
switch (rotation)
210210
{
211-
PDRectangle mediaBox = pdPage.getMediaBox();
212-
switch (rotation)
213-
{
214-
case 90:
215-
rotateAT.translate(mediaBox.getHeight(), 0);
216-
break;
217-
case 270:
218-
rotateAT.translate(0, mediaBox.getWidth());
219-
break;
220-
case 180:
221-
rotateAT.translate(mediaBox.getWidth(), mediaBox.getHeight());
222-
break;
223-
default:
224-
break;
225-
}
226-
rotateAT.rotate(Math.toRadians(rotation));
211+
case 0:
212+
transAT = AffineTransform.getTranslateInstance(-cropBox.getLowerLeftX(), cropBox.getLowerLeftY());
213+
break;
214+
case 90:
215+
rotateAT.translate(cropBox.getHeight(), 0);
216+
transAT = AffineTransform.getTranslateInstance(-cropBox.getLowerLeftY(), -cropBox.getLowerLeftX());
217+
break;
218+
case 270:
219+
rotateAT.translate(0, cropBox.getWidth());
220+
transAT = AffineTransform.getTranslateInstance(cropBox.getLowerLeftY(), cropBox.getLowerLeftX());
221+
break;
222+
case 180:
223+
rotateAT.translate(cropBox.getWidth(), cropBox.getHeight());
224+
transAT = AffineTransform.getTranslateInstance(cropBox.getLowerLeftX(), -cropBox.getLowerLeftY());
225+
break;
226+
default:
227+
break;
227228
}
228-
229-
// cropbox
230-
transAT = AffineTransform.getTranslateInstance(-cropBox.getLowerLeftX(), cropBox.getLowerLeftY());
229+
rotateAT.rotate(Math.toRadians(rotation));
231230

232231
g2d = image.createGraphics();
233232
g2d.setStroke(new BasicStroke(0.1f));

0 commit comments

Comments
 (0)