United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6359283 PrinterJob.pageDialog() ret. incorrect PageFormat when non-default printer used
JDK-6359283 : PrinterJob.pageDialog() ret. incorrect PageFormat when non-default printer used

Details
Type:
Bug
Submit Date:
2005-12-05
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp,windows_2000
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
When using PrinterJob.pageDialog() to get a PageFormat object, if the page size and margins are set with the default printer selected (in the "Printer" dialog), it behaves correctly. But when another printer is selected and a specific page format chosen, the returned imageableWidth and imageableHeight values of the PageFormat object are incorrect.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code below twice:
(1) with the desired printer set as default printer in the Windows Printer settings (so that no modification in the "Printer" dialog is necessary)
(2) with another printer set as default (so that changing the printer in the "Printer" dialog is necessary)
Select the same page size and margins for both runs.

Note that the selected printer is a HP DesignJet 500 42, which can print on very big page formats. Here the selected format was 1meter x 1.4 meter

Output for (1):

<beginning_of_output>
------- Page Format -------
ImageableX = 72.0
ImageableY = 72.0
ImageableWidth = 468.0
ImageableHeight = 648.0
Width = 612.0
Height = 792.0
------- Page Format -------
ImageableX = 72.0
ImageableY = 72.0
ImageableWidth = 2690.6456692913384
ImageableHeight = 3824.503937007874
Width = 2834.6456692913384
Height = 3968.503937007874
<end_of_output>

Output for (2):

<beginning_of_output>
------- Page Format -------
ImageableX = 72.0
ImageableY = 72.0
ImageableWidth = 468.0
ImageableHeight = 648.0
Width = 612.0
Height = 792.0
------- Page Format -------
ImageableX = 72.0
ImageableY = 72.0
ImageableWidth = 522.0
ImageableHeight = 707.9811023622048
Width = 2834.6456692913384
Height = 3968.503937007874
<end_of_output>

Code:


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The output should be the same, i.e. the imageableHeight and imageableWidth should be the same for both runs.
ACTUAL -
imageableHeight and imageableWidth differ between the two runs.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;

public class TestProg
{

	public static void main(String[] args)
	{
		PageFormat pf = new PageFormat();
		displayPageFormat(pf);
		pf = PrinterJob.getPrinterJob().pageDialog(new PageFormat());
		displayPageFormat(pf);
	}
	
	public static void displayPageFormat(PageFormat pf)
	{
		System.out.println("------- Page Format -------");
		System.out.println("ImageableX = " + pf.getImageableX());
		System.out.println("ImageableY = " + pf.getImageableY());
		System.out.println("ImageableWidth = " + pf.getImageableWidth());
		System.out.println("ImageableHeight = " + pf.getImageableHeight());
		System.out.println("Width = " + pf.getWidth());
		System.out.println("Height = " + pf.getHeight());
	}

}

---------- END SOURCE ----------

                                    

Comments
EVALUATION

This isn't obvious when using most printers, but using the
DesignJet with its large paper sizes makes it more clear what's happening.

We incorrectly validate the paper returned from the dialog against the device
capabilities values for margins using a DC from the original printer.
These impact the imageable area calculation
If the original printer can only handle small sizes, then the
reported bug is apparent.

Also we use to update that DC in a call to ResetDC() using a DEVMODE
returned by the page setup dialog.

Either we should prevent a user from being able to change the printer
at all from the page setup dialog, or, more likely I think,
we need to use a DC for the printer that's selected after we return.
We can get the selected printer from the returned devmode.hDevNames
and create a new DC for it .. its probably easiest to do this always,
although we could just do it in the event that the printer appears
to have changed.
                                     
2007-06-11



Hardware and Software, Engineered to Work Together