< prev index next >

src/java.desktop/share/classes/sun/print/PrintJob2D.java

Print this page

        

@@ -483,10 +483,28 @@
                 pageFormat.setOrientation(PageFormat.LANDSCAPE);
             } else {
                 pageFormat.setOrientation(PageFormat.PORTRAIT);
                 }
 
+            PageRanges pageRangesAttr
+                    = (PageRanges) attributes.get(PageRanges.class);
+            if (pageRangesAttr != null) {
+                int[][] range = pageRangesAttr.getMembers();
+
+                // Get the PageRanges from print dialog.
+                // But before setting JobAttributes to/from Page, set minPage
+                // as if from < min IAE is thrown.so update min Page first
+                // followed by to Page as again, if from < to, IAE is thrown
+                // and by default from/to = 1 so even if we set fromPage first
+                // to Page will remain 1, so from will be less than toPage.
+                // At last, reset minPage back to initial.
+                int minPage = this.jobAttributes.getMinPage();
+                this.jobAttributes.setMinPage(range[0][0]);
+                this.jobAttributes.setToPage(range[range.length - 1][1]);
+                this.jobAttributes.setFromPage(range[0][0]);
+                this.jobAttributes.setMinPage(minPage);
+            }
             printerJob.setPrintable(this, pageFormat);
 
         }
 
         return proceedWithPrint;
< prev index next >