Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8167102

[macosx] PrintRequestAttributeSet breaks page size set using PageFormat

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b166
    • OS:
      os_x

      Backports

        Description

        FULL PRODUCT VERSION :
        JDK 8u102 b14

        ADDITIONAL OS VERSION INFORMATION :
        OS X 10.11

        A DESCRIPTION OF THE PROBLEM :
        On OS X transferring an instance of "javax.print.attribute.PrintRequestAttributeSet" with at least one any attribute "javax.print.attribute.PrintRequestAttribute" to the method "java.awt.print.PrinterJob.print(PrintRequestAttributeSet)" leads to printing of a page with an incorrect paper size which is different from the expected paper size that was originally set to the printer job via "java.awt.print.PageFormat" instance by the call "java.awt.print.PrinterJob.setPrintable(Printable, PageFormat)". For example, in the test case listed below 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.

        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 listed below test case 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.

        ---------- BEGIN SOURCE ----------
        import javax.print.attribute.HashPrintRequestAttributeSet;
        import javax.print.attribute.PrintRequestAttributeSet;
        import javax.print.attribute.standard.Chromaticity;
        import java.awt.*;
        import java.awt.print.PageFormat;
        import java.awt.print.Paper;
        import java.awt.print.Printable;
        import java.awt.print.PrinterJob;

        public class PageSizeBug implements Printable {
            public static void main(String[] args) throws Exception{
                PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
                // Uncomment this next line to break the page's printed size and
                // default to printer's default (usually A4 or US Letter)
                // Re-comment this next line to allow page size to be printed correctly
                // This is not limited to Chromaticity, any new PrintRequestAttribute
                // will break the page's printed size
                //attributes.add(Chromaticity.MONOCHROME);

                //test data
                Paper paper = new Paper();
                paper.setSize(4 * 72, 6 * 72); //4x6in
                paper.setImageableArea(0, 0, 4 * 72, 6 * 72);
                PageFormat pf = new PageFormat();
                pf.setPaper(paper);

                PageSizeBug printable = new PageSizeBug();
                PrinterJob job = PrinterJob.getPrinterJob();
                job.setPrintable(printable, pf);
                job.print(attributes);
                System.exit(0);
            }

            @Override
            public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
                g.setColor(Color.RED);
                g.drawRect((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY(),
                        (int)pageFormat.getImageableWidth() -1, (int)pageFormat.getImageableHeight() -1);
                return pageIndex == 0? PAGE_EXISTS:NO_SUCH_PAGE;
            }
        }
        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alitvinov Anton Litvinov
                  Reporter:
                  shadowbug Shadow Bug
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Due:
                    Created:
                    Updated:
                    Resolved: