You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2024/12/28 11:30:48 UTC

svn commit: r1922720 - /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java

Author: tilman
Date: Sat Dec 28 11:30:48 2024
New Revision: 1922720

URL: http://svn.apache.org/viewvc?rev=1922720&view=rev
Log:
PDFBOX-3690: use cropbox instead of mediabox sizes / compensate for cropbox origins when rotating

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java?rev=1922720&r1=1922719&r2=1922720&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java Sat Dec 28 11:30:48 2024
@@ -206,28 +206,27 @@ public class DrawPrintTextLocations exte
         // 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));