aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Printing from a J2EE app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Printing from a J2EE app" Watch "Printing from a J2EE app" New topic
Author

Printing from a J2EE app

john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
Anyone got any experience of printing from within a J2EE app? We have stored against our user records a "print address" fields which points to a networked printer. I need to fire off print jobs from within the Session Facade which will spool to this named printer. All clients will be on the same network (though not necessarily in the same domain) - the app server will be on the same network too. This needs to be 100% cross-platform (Linux, Windows, UNIX - the lot) I know that there is a Java Print Service which I understand is primarily for AWT/Swing client-apps. Has any one used it from the server side? Is is possible? Any gotchas I should watch out for? Or is it just a silly idea?
Any ideas/experience is very appreciated.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Any kind of IO activity is not recommended by the EJB Specs due to portability issues. Isn't printing a type of IO activity?
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
Yes - though that doesn't necessarily stop you doing it! However - I was going to do it through my own JCA resource manager, but I'm not sure if its worth writing this unless the print service stuff is good enough to use. I'm beginning to discover it maybe is not. So if anyone has had a similar piece of functionality to implement (i.e. the app server building documents and scheduling them jobs on one of a number of networked printers) I'd be very interested to hear about it.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The Java Print Service API (JSR-006) allows printing pretty much anything -- as long as you make your "anything" implement the correct interfaces...
There's a nice example in the user guide.
As to where you should invoke the Java Print Service API from, I'd say create a printable document (javax.print.Doc), put it into a JMS queue, and let an MDB make the call to the JPS API for the actual printing. Then again, I'm really not aware of how resource intensive the actual print call is so maybe it would be ok to leave the MDB out of the picture and let the EJB do everything.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
Cheers for your reply. I had started like this - print message to MDB, MDB doing the actual Printing service stuff. But I was finding that there are problems with what the avaliable print services can actually do. E.g. despite having a pretty bog-standard printer/printer driver and the app running on Windows XP, a lot of the defined attributes were not supported by the underlying print service (I couldn't enforce paper size, or orientation, or number of copies etc.) What I am finding is that despite the Print Service offering a platform independent route into avaliable printing services, the actual functianality is very much limited by the printer driver. No big suprise there, its just *how* limitied it is that is the problem. Looks like I might have to give this up.
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
By the way, is JSP part of J2EE, and isn't there a print option on a web browser.
I am sure, your print batch function can not be accomplished by the above.
But I am just replying to "Printing not allowed in J2EE" comments.
Dan.


Kishore
SCJP, blog
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
Indeed it is Dan, and that would be the simple way of doing it. Unfortunately we need people to be able to send print jobs to remote printers without having the configuration overhead of ensuring that every client has correctly configured the avaliable printers in their OS. Also, the client won't necessarily know the action they perform in the app results in a printout to another user, most probably in a completely different location from them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing from a J2EE app
 
Similar Threads
Printing issue
Printing
Printing issue
printing to specific network printer
Printing in Unix