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 2015/12/30 12:29:55 UTC

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

Author: tilman
Date: Wed Dec 30 11:29:54 2015
New Revision: 1722316

URL: http://svn.apache.org/viewvc?rev=1722316&view=rev
Log:
PDFBOX-3175: adjust transform for rotated pages

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=1722316&r1=1722315&r2=1722316&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 Wed Dec 30 11:29:54 2015
@@ -205,9 +205,32 @@ public class DrawPrintTextLocations exte
             flip.translate(0, getCurrentPage().getBBox().getHeight());
             flip.scale(1, -1);
             s = flip.createTransformedShape(s);
-            
+
+            AffineTransform transform = g2d.getTransform();
+            int rotation = getCurrentPage().getRotation();
+            if (rotation != 0)
+            {
+                PDRectangle mediaBox = getCurrentPage().getMediaBox();
+                switch (rotation)
+                {
+                    case 90:
+                        g2d.translate(mediaBox.getHeight(), 0);
+                        break;
+                    case 270:
+                        g2d.translate(0, mediaBox.getWidth());
+                        break;
+                    case 180:
+                        g2d.translate(mediaBox.getWidth(), mediaBox.getHeight());
+                        break;
+                }
+                g2d.rotate(Math.toRadians(rotation));
+            }
             g2d.setColor(Color.blue);
             g2d.draw(s);
+            if (rotation != 0)
+            {
+                g2d.setTransform(transform);
+            }
         }
     }