-
Bug
-
Resolution: Fixed
-
P4
-
6u11
-
b127
-
x86
-
windows_xp
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
JHava HotSpot(TM) Client VM (build 11.0-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows XP
EXTRA RELEVANT SYSTEM CONFIGURATION :
java.awt.printerjob=sun.awt.windows.WPrinterJob,
A DESCRIPTION OF THE PROBLEM :
When I request a PageFormat with a PrintRequestAttributeSet that contains the selected values. I get a PageFormat without this specified configuration.
I use this PageFormat object to create a Pageable object.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the sample.
Choose a different margin configuration with the dialog.
Print.
Look at the margins.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The margins of the page were what I stablished
ACTUAL -
Always I get the same margins
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There isn't any error message.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Impresiones extends JFrame
{
private static final long serialVersionUID = 1L;
PrinterJob job;
public static void main (String args[])
{
Runnable r = new Runnable()
{
public void run ()
{
new Impresiones();
}
};
SwingUtilities.invokeLater(r);
}
public Impresiones ()
{
// Iniciamos el servicio de impresión
job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
// Here you could see the PageFormat with an empty PrintRequestAttributeSet
PageFormat pf2 = job.getPageFormat(pras);
boolean aceptado = job.printDialog(pras);
if (!aceptado)
{
return;
}
// Here you could see the PageFormat with the PrintRequestAttributeSet stablished
// by the printDialog and you could see that we have the same result or almost a
// different one from what we expectted.
pf2 = job.getPageFormat(pras);
// Print
PageFormat pf = job.getPageFormat(pras);
Imprimible i = new Imprimible();
Paginable p = new Paginable(i, pf);
job.setPageable(p);
try
{
job.print();
}
catch (PrinterException e)
{
System.out.println("Printing error:");
System.out.println(e.getMessage());
}
}
}
class Paginable implements Pageable
{
PageFormat pf;
Imprimible i;
public Paginable (Imprimible i, PageFormat pf)
{
this.i = i;
this.pf = pf;
}
public int getNumberOfPages()
{
return 1;
}
public PageFormat getPageFormat(int arg0) throws IndexOutOfBoundsException
{
return pf;
}
public Printable getPrintable(int arg0) throws IndexOutOfBoundsException
{
return i;
}
}
class Imprimible implements Printable
{
public int print(Graphics arg0, PageFormat arg1, int arg2)
throws PrinterException
{
if (arg2!=0) return Printable.NO_SUCH_PAGE;
double x = arg1.getImageableX();
double y = arg1.getImageableY();
double ancho = arg1.getImageableWidth();
double alto = arg1.getImageableHeight();
arg0.drawOval((int)ancho/2, (int)alto/2, (int)ancho/4, (int)alto/4);
arg0.drawString("Print test", (int)(x + 10), (int)(y + 10));
return Printable.PAGE_EXISTS;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I haven't found any way to workaround.
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
JHava HotSpot(TM) Client VM (build 11.0-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows XP
EXTRA RELEVANT SYSTEM CONFIGURATION :
java.awt.printerjob=sun.awt.windows.WPrinterJob,
A DESCRIPTION OF THE PROBLEM :
When I request a PageFormat with a PrintRequestAttributeSet that contains the selected values. I get a PageFormat without this specified configuration.
I use this PageFormat object to create a Pageable object.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the sample.
Choose a different margin configuration with the dialog.
Print.
Look at the margins.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The margins of the page were what I stablished
ACTUAL -
Always I get the same margins
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There isn't any error message.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Impresiones extends JFrame
{
private static final long serialVersionUID = 1L;
PrinterJob job;
public static void main (String args[])
{
Runnable r = new Runnable()
{
public void run ()
{
new Impresiones();
}
};
SwingUtilities.invokeLater(r);
}
public Impresiones ()
{
// Iniciamos el servicio de impresión
job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
// Here you could see the PageFormat with an empty PrintRequestAttributeSet
PageFormat pf2 = job.getPageFormat(pras);
boolean aceptado = job.printDialog(pras);
if (!aceptado)
{
return;
}
// Here you could see the PageFormat with the PrintRequestAttributeSet stablished
// by the printDialog and you could see that we have the same result or almost a
// different one from what we expectted.
pf2 = job.getPageFormat(pras);
PageFormat pf = job.getPageFormat(pras);
Imprimible i = new Imprimible();
Paginable p = new Paginable(i, pf);
job.setPageable(p);
try
{
job.print();
}
catch (PrinterException e)
{
System.out.println("Printing error:");
System.out.println(e.getMessage());
}
}
}
class Paginable implements Pageable
{
PageFormat pf;
Imprimible i;
public Paginable (Imprimible i, PageFormat pf)
{
this.i = i;
this.pf = pf;
}
public int getNumberOfPages()
{
return 1;
}
public PageFormat getPageFormat(int arg0) throws IndexOutOfBoundsException
{
return pf;
}
public Printable getPrintable(int arg0) throws IndexOutOfBoundsException
{
return i;
}
}
class Imprimible implements Printable
{
public int print(Graphics arg0, PageFormat arg1, int arg2)
throws PrinterException
{
if (arg2!=0) return Printable.NO_SUCH_PAGE;
double x = arg1.getImageableX();
double y = arg1.getImageableY();
double ancho = arg1.getImageableWidth();
double alto = arg1.getImageableHeight();
arg0.drawOval((int)ancho/2, (int)alto/2, (int)ancho/4, (int)alto/4);
arg0.drawString("Print test", (int)(x + 10), (int)(y + 10));
return Printable.PAGE_EXISTS;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I haven't found any way to workaround.