using javax.print API

Picolet Antoine antoinepicolet at hotmail.com
Thu Apr 17 10:50:36 CEST 2003


Hi,

I am trying to use the javax.print API for managing printjobs. Everything 
works for
submitting print jobs, but I cannot cancel it with Java.
I tried on a Windows 2k machine and on a Linux RedHat 7.3 machine, with the 
same code,
which produces the same result: a printjob is sent to the printer and, when 
I try to cancel
it from Java, I get an error 'Job could not be cancelled' originating from a 
sun.print class.
My question is : does the javax.print API cancel feature work for anybody, 
or does somebody
know if it is meant to work ?

the code:

////////////////////////////////////////////////////////////////////////////////////////////
import javax.print.*;
import java.io.*;
import java.lang.reflect.*;

class PrintTest
{
	public static void main(String[] args)
	{

		testPrinter= PrintServiceLookup.lookupDefaultPrintService();

		FileInputStream psStream = null;
		try
		{
			psStream = new FileInputStream("tiger.ps");
		}
		catch (FileNotFoundException ffne)
		{
		}

		Doc testDoc = new SimpleDoc(psStream, DocFlavor.INPUT_STREAM.AUTOSENSE, 
null);
		DocPrintJob job = testPrinter.createPrintJob();
		CancelablePrintJob canJob = (CancelablePrintJob)job;

		try
		{
			System.out.println("Printing 'tiger.ps'...");
			canJob.print(testDoc, null);
		}
		catch(PrintException pe)
		{
			pe.printStackTrace();
			System.exit(0);
		}


		try
		{
			System.out.println("Cancelling print job...");
			canJob.cancel();
		}
		catch(PrintException pe)
		{
			pe.printStackTrace();
			System.exit(0);
		}

	}
}
/////////////////////////////////////////////////////////////////////////////////////////////

the output: on a piece of paper, a splendid tiger face from the Ghostscript 
distribution, and
on the screen:

	Printing 'tiger.ps'...
	Cancelling print job...
	javax.print.PrintException: Job could not be cancelled.
        	at sun.print.UnixPrintJob.cancel(UnixPrintJob.java:877)
	        at PrintTest.main(PrintTest.java:102)

On the Windows machine, the originating class being sun.print.Win32PrintJob, 
but the remaining
being the same.

I tried to figure out if the tiger.ps was to small a file, immediately 
printed, and the error meaning
the job was already finished, so I tried with a 500-page text doc, the 
result was the same.




_________________________________________________________________
MSN Search, le moteur de recherche qui pense comme vous !  
http://search.msn.fr/worldwide.asp



More information about the kde-print mailing list