Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2007, 05:52 PM
Member
 
Join Date: Oct 2007
Posts: 2
remnahush is on a distinguished road
[Java Printing]
I'm developing a printing functionality using Java Print Service API.

I found the way to send escape codes to the printer, but I don't know how to retrieve a printer feedback or how to ask to the printer if it has paper, and other function issues like lost of communication...

I use the javax.print.event but just the events printDataTransferCompleted and printJobNoMoreEvents works fine. Even when I turn off the printer, disconnect the cable, let it without paper, no other event is fired.

Does anybody know how to get this kind of response from a printer using java?

Thank you very much for any help
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-08-2007, 04:28 PM
Member
 
Join Date: Nov 2007
Location: Singapore
Posts: 3
made.putrama is on a distinguished road
Last time I had a similar requirement to be done in a web application.
But I couldn't find on how to detect the connection or I/O problem from the printer. But I think the code was able to detect some of the events that you’ve mentioned.

I used javax.print.DocPrintJob and implement its listener to return a flag whenever the corresponding event occurs upon printing.
There are some methods that you would want to implement. But it may need to check whether one of the methods is supported by the printer.
You may want to use javax.print.attribute.* classes in order to know the properties of your printer.

Here is the chunk of the code:
static class PrintJobWatcher
{
boolean done = true;
PrintJobWatcher(DocPrintJob job)
{
job.addPrintJobListener(
new PrintJobAdapter()
{
public void printJobCanceled(PrintJobEvent pje)
{
log.debug("Printing job was cancelled.");
notDone();
}
public void printJobFailed(PrintJobEvent pje)
{
log.error("Printing job failed.");
notDone();
}
public void printJobRequiresAttention()
{
log.error("Rectifiable problem occured (e.g. printer out of paper).");
notDone();
}
void notDone()
{
synchronized (PrintJobWatcher.this)
{
done = false;
PrintJobWatcher.this.notify();
}
}
}
);
}
}


And here the printing watcher is registered:

InputStream in = new FileInputStream( <<File instance>> );
in = new BufferedInputStream(in);

AttributeSet aset = new HashAttributeSet();
aset.add( new PrinterName( <<Printer name>>, null ) );
PrintService[] printers = PrintServiceLookup.lookupPrintServices( null, aset );
UAssert.check( printers.length > 0, "No printer found." );

//to use the 1st printer
PrintService service = printers[0];

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(in, flavor, null);
DocPrintJob pj = service.createPrintJob();
PrintJobWatcher prWatcher = new PrintJobWatcher(pj);
PrintRequestAttributeSet prAset = new HashPrintRequestAttributeSet();
prAset.add(MediaSizeName.ISO_A4);
pj.print(doc, prAset);

in.close();


Regards,
Putrama
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem after Printing GUI. coldblood22 AWT / Swing 1 04-05-2008 03:43 PM
Printing (no dialog) Java Tip Java Tips 0 02-04-2008 10:36 AM
Problem in printing java graphics Mahendra Java 2D 0 01-23-2008 01:45 PM
Printing using java ramachandran Advanced Java 1 01-05-2008 11:16 AM
printing problem ntpl AWT / Swing 0 11-27-2007 12:20 PM


All times are GMT +3. The time now is 12:52 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org