pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1601447 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java
Date Mon, 09 Jun 2014 17:28:22 GMT
Author: lehmi
Date: Mon Jun  9 17:28:21 2014
New Revision: 1601447

URL: http://svn.apache.org/r1601447
Log:
PDFBOX-2119: provide the correct page format when calling getPageFormat

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java?rev=1601447&r1=1601446&r2=1601447&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageable.java Mon
Jun  9 17:28:21 2014
@@ -61,10 +61,9 @@ public class PDPageable implements Pagea
      *
      * @param document PDF document
      * @param printerJob printer job
-     * @throws IllegalArgumentException if an argument is <code>null</code>
      * @throws PrinterException if the document permissions prevent printing
      */
-    public PDPageable(PDDocument document, PrinterJob printerJob) throws IllegalArgumentException,
PrinterException
+    public PDPageable(PDDocument document, PrinterJob printerJob) throws PrinterException
     {
         if (document == null || printerJob == null)
         {
@@ -88,10 +87,9 @@ public class PDPageable implements Pagea
      * a default printer job returned by {@link PrinterJob#getPrinterJob()}.
      *
      * @param document PDF document
-     * @throws IllegalArgumentException if the argument is <code>null</code>
      * @throws PrinterException if the document permissions prevent printing
      */
-    public PDPageable(PDDocument document) throws IllegalArgumentException, PrinterException
+    public PDPageable(PDDocument document) throws PrinterException
     {
         this(document, PrinterJob.getPrinterJob());
     }
@@ -123,13 +121,10 @@ public class PDPageable implements Pagea
      *
      * @param i page index, zero-based
      * @return page format
-     * @throws IndexOutOfBoundsException if the page index is invalid
      */
-    public PageFormat getPageFormat(int i) throws IndexOutOfBoundsException
+    public PageFormat getPageFormat(int i)
     {
-        PageFormat format = job.defaultPage();
-
-        PDPage page = pages.get(i); // can throw IOOBE
+        PDPage page = pages.get(i);
         Dimension media = page.findMediaBox().createDimension();
         Dimension crop = page.findCropBox().createDimension();
 
@@ -142,20 +137,22 @@ public class PDPageable implements Pagea
             diffHeight = (media.getHeight() - crop.getHeight()) / 2.0;
         }
 
-        Paper paper = format.getPaper();
-        if (media.getWidth() < media.getHeight())
-        {
-          format.setOrientation(PageFormat.PORTRAIT);
-          paper.setImageableArea(diffWidth, diffHeight, crop.getWidth(), crop.getHeight());
+        PageFormat wantedFormat = new PageFormat();
+        Paper wantedPaper = new Paper();
+        if (media.getWidth() <= media.getHeight())
+        {
+            wantedFormat.setOrientation(PageFormat.PORTRAIT);
+            wantedPaper.setSize(media.getWidth(), media.getHeight());
+            wantedPaper.setImageableArea(diffWidth, diffHeight, crop.getWidth(), crop.getHeight());
         }
         else
         {
-          format.setOrientation(PageFormat.LANDSCAPE);
-          paper.setImageableArea(diffHeight, diffWidth, crop.getHeight(), crop.getWidth());
+            wantedFormat.setOrientation(PageFormat.LANDSCAPE);
+            wantedPaper.setSize(media.getHeight(), media.getWidth());
+            wantedPaper.setImageableArea(diffHeight, diffWidth, crop.getHeight(), crop.getWidth());
         }
-        format.setPaper(paper);
-
-        return format;
+        wantedFormat.setPaper(wantedPaper);
+        return job.validatePage(wantedFormat);
     }
 
     /**
@@ -166,9 +163,8 @@ public class PDPageable implements Pagea
      *
      * @param i page index, zero-based
      * @return printable
-     * @throws IndexOutOfBoundsException if the page index is invalid
      */
-    public Printable getPrintable(int i) throws IndexOutOfBoundsException
+    public Printable getPrintable(int i)
     {
         return pages.get(i);
     }



Mime
View raw message