--- old/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java 2017-03-17 16:18:07.000000000 +0300 +++ new/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java 2017-03-17 16:18:07.000000000 +0300 @@ -886,12 +886,47 @@ } } - protected PageFormat getPageFormatFromAttributes() { - if (attributes == null || attributes.isEmpty()) { + protected PageFormat getPageFormatFromAttributes() { + if (attributes == null || attributes.isEmpty()) { return null; } - return attributeToPageFormat(getPrintService(), this.attributes); - } + + PageFormat newPf = attributeToPageFormat( + getPrintService(), attributes); + PageFormat oldPf = null; + Pageable pageable = getPageable(); + if ((pageable != null) && + (pageable instanceof OpenBook) && + ((oldPf = pageable.getPageFormat(0)) != null) && + (newPf != null)) { + // If the attribute set 'attributes' does not contain either + // orientation, or media, or imageable area attributes, then use + // in the new 'PageFormat' corresponding values of the existing + // 'PageFormat'. + if (attributes.get(OrientationRequested.class) == null) { + newPf.setOrientation(oldPf.getOrientation()); + } + + Paper newPaper = newPf.getPaper(); + Paper oldPaper = oldPf.getPaper(); + boolean oldPaperValWasSet = false; + if (attributes.get(MediaSizeName.class) == null) { + newPaper.setSize(oldPaper.getWidth(), oldPaper.getHeight()); + oldPaperValWasSet = true; + } + if (attributes.get(MediaPrintableArea.class) == null) { + newPaper.setImageableArea( + oldPaper.getImageableX(), oldPaper.getImageableY(), + oldPaper.getImageableWidth(), + oldPaper.getImageableHeight()); + oldPaperValWasSet = true; + } + if (oldPaperValWasSet) { + newPf.setPaper(newPaper); + } + } + return newPf; + } /**