pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1712887 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing: PDFPageable.java PDFPrintable.java
Date Fri, 06 Nov 2015 00:26:02 GMT
Author: jahewson
Date: Fri Nov  6 00:26:02 2015
New Revision: 1712887

URL: http://svn.apache.org/viewvc?rev=1712887&view=rev
Log:
PDFBOX-2930: printing support for rotated documents

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java?rev=1712887&r1=1712886&r2=1712887&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java Fri Nov
 6 00:26:02 2015
@@ -104,7 +104,7 @@ public final class PDFPageable extends B
     public PageFormat getPageFormat(int pageIndex)
     {
         PDPage page = document.getPage(pageIndex);
-        PDRectangle mediaBox = page.getMediaBox();
+        PDRectangle mediaBox = PDFPrintable.getRotatedMediaBox(page);
         PDRectangle cropBox = PDFPrintable.getRotatedCropBox(page);
         
         // Java does not seem to understand landscape paper sizes, i.e. where width >
height, it

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java?rev=1712887&r1=1712886&r2=1712887&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java Fri Nov
 6 00:26:02 2015
@@ -210,4 +210,25 @@ public final class PDFPrintable implemen
             return cropBox;
         }
     }
+
+    /**
+     * This will find the MediaBox with rotation applied, for this page by looking up the
hierarchy
+     * until it finds them.
+     *
+     * @return The MediaBox at this level in the hierarchy.
+     */
+    static PDRectangle getRotatedMediaBox(PDPage page)
+    {
+        PDRectangle mediaBox = page.getMediaBox();
+        int rotationAngle = page.getRotation();
+        if (rotationAngle == 90 || rotationAngle == 270)
+        {
+            return new PDRectangle(mediaBox.getLowerLeftY(), mediaBox.getLowerLeftX(),
+                                   mediaBox.getHeight(), mediaBox.getWidth());
+        }
+        else
+        {
+            return mediaBox;
+        }
+    }
 }



Mime
View raw message