--- old/src/java.desktop/share/classes/sun/print/PrintJob2D.java 2016-03-28 14:00:15.002204800 +0530 +++ new/src/java.desktop/share/classes/sun/print/PrintJob2D.java 2016-03-28 14:00:14.442633800 +0530 @@ -483,8 +483,26 @@ 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); }