JDK-8201818 : [macosx] Printing attributes break page size set via "java.awt.print.Book" object
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,8u112,8u162,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2018-04-18
  • Updated: 2022-10-24
  • Resolved: 2018-08-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12 JDK 8 Other
11.0.3-oracleFixed 12 b14Fixed 8u181Fixed openjdk8u212Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
JDK 8u162 b12

ADDITIONAL OS VERSION INFORMATION :
OS X 10.11

A DESCRIPTION OF THE PROBLEM :
If "javax.print.attribute.PrintRequestAttributeSet" which contains at least one any printing attribute is transferred to "java.awt.print.PrinterJob.print(PrintRequestAttributeSet)" method, then a page size specified through "java.awt.print.Book" object associated with the printer job is not respected and the printed page size equals the default page size of the printer.

For example, in the attached test case "PrintingAttributeBreaksBookPageSize.java" the printed page size should be exactly 4" x 6", while adding a single "javax.print.attribute.PrintRequestAttribute" leads to a much bigger size of the printed page. The difference is demonstrated in the attached following PDF files:
- "PrintedPageWithCorrectSize.pdf" - correct page size.
- "PrintedPageWithWrongSize.pdf" - incorrect page size.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.  Configure a default printer for the system to use either a virtual printer, for example "PDF Printer Lite", "PDFwriter for Mac", or a printer capable of printing a page with 4" x 6" size.
2.  Compile and run the attached test case "PrintingAttributeBreaksBookPageSize.java" leaving the line "attributes.add(Chromaticity.MONOCHROME);" commented out.
3.  Notice that 4" x 6" page is properly printed.
4.  Uncomment the line "attributes.add(Chromaticity.MONOCHROME);", recompile and run the test case.
5.  Notice that the printed page size is different from the expected 4'' x 6'' and corresponds to the printer's default page size.
Comments
Fix Request This fixes the printing bug on Mac OS X. Having this backport also keeps JDKs in sync: I see 11.0.3-oracle. Patch applies cleanly to 11u. It passes Linux and Mac OS X builds. I also verified the manual test on Mac OS X Yosemite with PDFWriter printer.
20-02-2019

URL: http://hg.openjdk.java.net/jdk/jdk/rev/451ec22b1a46 User: prr Date: 2018-09-27 18:41:13 +0000
27-09-2018

URL: http://hg.openjdk.java.net/jdk/client/rev/451ec22b1a46 User: alitvinov Date: 2018-08-27 17:30:15 +0000
27-08-2018

This issue is a bug in JDK, because: 1. According to the documentation for the method "java.awt.print.PrinterJob.print(PrintRequestAttributeSet)" from Java Platform SE 8 API Specification, if a user sets "java.awt.print.Pageable" object for "PrinterJob", then printing attributes related to media size, imageable area, page orientation will not influence anyhow the "PageFormat" object used for printing, and only "PageFormat" provided by the "Pageable" object will be used. Statement: "For clients of the Pageable interface, the PageFormat will always be as supplied by that interface, on a per page basis." Specification URL #1: https://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html#print-javax.print.attribute.PrintRequestAttributeSet- 2. Documentation on the method "java.awt.print.PrinterJob.printDialog(PrintRequestAttributeSet)" acknowledges the point #1 by the statement "If using the Pageable interface, clients which intend to use media selected by the user must create a PageFormat derived from the user's selections.". Specification URL #2: https://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html#printDialog-javax.print.attribute.PrintRequestAttributeSet-
17-08-2018

The following 3 files were attached to the bug: 1. "PrintingAttributeBreaksBookPageSize.java" - the compilable test case; 2. "PrintedPageWithCorrectSize.pdf" - the document with a correct expected page size printed using the test case; 3. "PrintedPageWithWrongSize.pdf" - the document with a wrong page size printed using the test case. The bug was reproduced on OS X 10.13.3 using the virtual printer "PDFwriter for Mac": - with JDK 12 compiled from the latest version of the source code in the repository "http://hg.openjdk.java.net/jdk/client" - with JDK 8u181 b13, JDK 8u162 b12, JDK 8u112 b16.
13-08-2018