JDK-6680634 : Printing: "Collate" is ignored under Windows Vista x64
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.0,6,6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_vista,windows_7
  • CPU: x86
  • Submitted: 2008-03-26
  • Updated: 2010-04-23
  • Resolved: 2009-11-08
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 6 JDK 7
6u18 b04Fixed 7Fixed
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_15"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
Java HotSpot(TM) Client VM (build 1.5.0_15-b04, mixed mode, sharing)

java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

java version "1.6.0_10-beta"
Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b13)
Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b24)
Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6001]

EXTRA RELEVANT SYSTEM CONFIGURATION :
HP LaserJet 1100
Epson Stylus DX5050

A DESCRIPTION OF THE PROBLEM :
When printing multiple copies of a document the setting "Collate" is ignored in the native Dialog. Printing order is always n times page 1, n times page 2, ...

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the source.
2. Select "Collate" in the print dialog.
3. Start printing

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The result should contain 4 pages. Each containing one number in the following order: 0, 1, 0, 1
ACTUAL -
The result contains 4 pages. Each containing one number in the following order: 0, 0, 1, 1

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PrintTest {

    public static class TwoPages implements Printable {
        public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
                throws PrinterException {
            // print only two pages
            if (pageIndex > 1) {
                return NO_SUCH_PAGE;
            }

            // Ensure that text is visible
            float x = (float) (pageFormat.getImageableX() + pageFormat
                    .getImageableWidth() / 2);
            float y = (float) (pageFormat.getImageableY() + pageFormat
                    .getImageableHeight() / 2);

            // print text
            Graphics2D g2d = (Graphics2D) graphics;
            g2d.drawString("" + pageIndex, x, y);

            return PAGE_EXISTS;
        }
    }

    public static void main(String[] args) throws PrinterException {
        PrinterJob job = PrinterJob.getPrinterJob();
        PageFormat pf = job.defaultPage();
        job.setCopies(2);
        job.setPrintable(new TwoPages(), pf);

        if (job.printDialog()) {
            job.print();
        }
    }
}
---------- END SOURCE ----------

Comments
EVALUATION Caused by a change in the way Windows Vista/7 handles copies and collation values returned by the native print dialog. We relied on DEVMODE to have the correct value and it used to work in XP and previous Windows even though we did not set the flag PD_USEDEVMODECOPIESANDCOLLATE but now it stopped working in Vista/7. It's a known issue for copies but assumed to be the same with collation since they share the same flag. From MSDN: "To ensure that PrintDlg or PrintDlgEx returns the correct values in the dmCopies and dmCollate members of the DEVMODE structure, set PD_RETURNDC = TRUE and PD_USEDEVMODECOPIESANDCOLLATE = TRUE. In so doing, the nCopies member of the PRINTDLG structure is always 1 and PD_COLLATE is always FALSE. ... Warning On Windows Vista and Windows 7, when you call PrintDlg or PrintDlgEx with PD_RETURNDC set to TRUE and PD_USEDEVMODECOPIESANDCOLLATE set to FALSE, the PrintDlg or PrintDlgEx function sets the number of copies in the nCopies member of the PRINTDLG structure, and it sets the number of copies in the structure represented by the hDC member of the PRINTDLG structure."
09-10-2009