JDK-5044030 : Drawing problem with printer graphics on certain printers
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-05-07
  • Updated: 2008-11-25
  • Resolved: 2008-11-25
Related Reports
Duplicate :  
Description
Name: rv122619			Date: 05/07/2004

Using jdk1.5.0 (build 49)

Run the following program, which prints a line of text using two different strategies.  The first prints the default way, passing no arguments to printDialog() and print().  The second way passes a PrintRequestAttributeSet to both functions.  In jdk1.4.2 (b28), the output from both versions is the same.  However, in 1.5.0 (with a particular printer, see below), the output of the first print attempt appears to be compressed horizontally.  The same number of characters is printed by each strategy;  however, the characters printed using the 1st strategy are narrower.  The line of text is truncated about 2/3 of the way across the page instead of at the default 1 inch margin.  In a previous test, I confirmed that filling the background of the imageable rectangle only fills up 2/3 of the page across (but seems okay vertically).  

Printing to a file (and viewing with Ghostscript) shows the same behavior.

On two printers HP LaserJet 5Si/5Si MX PS and HP LaserJet IIISi Postscript v52.3, the output is the same using either strategy.  However, the printer where I see the difference is a Tektronix Phaser 850 DP (color and higher resolution I think).


import java.awt.Graphics;
import java.awt.print.PageFormat;
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;

public class PrintTest implements Printable
{
	/**
	 * 
	 */
	public PrintTest()
	{
		super();
	}

	public static void main(String[] args)
	{
		PrintTest pt=new PrintTest();
		
		pt.printFails();
		pt.printWorks();
	}
	
	public void printFails()
	{
		PrinterJob job=PrinterJob.getPrinterJob();
		job.setPrintable(this);
		if (job.printDialog())
		{
			try
			{
				job.print();
			}
			catch (PrinterException e)
			{
				e.printStackTrace();
			}
		}
	}
	
	public void printWorks()
	{
		PrinterJob job=PrinterJob.getPrinterJob();
		job.setPrintable(this);
		PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();
		if (job.printDialog(settings))
		{
			try
			{
				job.print();
			}
			catch (PrinterException e)
			{
				e.printStackTrace();
			}
		}
	}

	public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
	{
		if (pageIndex>0)
		{
			return NO_SUCH_PAGE;
		}
		
		StringBuffer s=new StringBuffer();
		for (int i=0;i<10;i++)
		{
			s.append("1234567890ABCDEFGHIJ");
		}
		
		int x=(int) pageFormat.getImageableX();
		int y=(int) (pageFormat.getImageableY()+50);
		graphics.drawString(s.toString(), x, y);
		
		return PAGE_EXISTS;
	}
}

======================================================================

Comments
EVALUATION Also see bug 6357932
01-12-2005

WORK AROUND Name: rv122619 Date: 05/07/2004 None ======================================================================
17-09-2004

EVALUATION Name: osR10079 Date: 05/11/2004 The problem is reporoducible with b32, so it is not a recent regression. I reassign the bug to the 2D team for initial evaluation beacuse printing is under their responsibility. ###@###.### 2004-05-11 ====================================================================== Too late for tiger. ###@###.### 2004-06-01
11-05-2004