aspose file tools*
The moose likes Java in General and the fly likes Printing in Unix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Printing in Unix" Watch "Printing in Unix" New topic
Author

Printing in Unix

Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
I have deployed my java application on a Solaris system.A network printer is connected to this Solaris machine.And from within the java application I am firing a print using Java's Print API.
I am printing a GIF document.But the printer outputs junk characters onto the pages.When the same thing is done on an application deployed on a Windows system and print is fired to a printer attached to this Windows system it prints properly.
Can someone advise me on what would be the problem and how to rectify it?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Is the Solaris system running Xwindows?
I had to install Xvfb to get headless mode to work on my Solaris servers for JDK 1.4.
Here is a more recent article on headless mode under Java 6.


[How To Ask Questions On JavaRanch]
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
Well I am not aware of what XWindows is and what is it's purpose in a Solaris System.Can you please tell me?Also can someone please let me know what would be any other probable reason because of which I am facing the problem?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Wiki entry for Xwindows
Do you have a graphical display on this machine or do you just have a command line?
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
I am not sure if whether the system has a Graphical Display matters.All I am doing is deploying a Java application as a jar in the Solaris Server.Now when the application is run it fires a print to a Nwtwork Printer through the Java Print API.All this is done without using any GUI or Swing application which would require manual selections.
Here everything is done without manual intervention at all.The application gets the list of printservices configured for the Server and fires the print to the designated printer.The same application deployed on Windows works fine and my GIF document gets printed properly on the printer.But with the application deployed on Solaris the printer spews out junk characters when GIF document is printed.I just need to know how to circumvent this problem.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Originally posted by Nikhil Sun:
I am not sure if whether the system has a Graphical Display matters.

Printing requires a graphical environment to render graphics on a virtual "page" to send to the printer. Windows always has a graphical environment (hence the name). On a Unix variant like Solaris, the graphical environment is an optional component.
As for how to circumvent this problem, see the links I posted in my original reply (it may be as easy as setting the system property "-Djava.awt.headless= true" on your server).
[ June 20, 2008: Message edited by: Joe Ess ]
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
I see that Xvfb is there on the Solaris system.I also set the System property java.awt.headless as true inside my application.
Inspite of this when I try and print I am getting the following Exception when I try to print a txt file:

java.awt.print.PrinterException: Printer is not accepting job.
2008-07-02 13:15:57.108 [info] at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1231)
2008-07-02 13:15:57.108 [info] at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1197)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.runtime.printer.TextPrinter.doPrint(TextPrinter.java:216)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.runtime.printer.TextPrinter.print(TextPrinter.java:177)
2008-07-02 13:15:57.108 [info] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2008-07-02 13:15:57.108 [info] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2008-07-02 13:15:57.108 [info] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2008-07-02 13:15:57.108 [info] at java.lang.reflect.Method.invoke(Method.java:585)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.runtime.dispatcher.PrintDispatcher.printDocs(PrintDispatcher.java:141)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.runtime.dispatcher.PrintDispatcher.process(PrintDispatcher.java:85)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.runtime.dispatcher.PrintDispatcher.prepareToPrint(PrintDispatcher.java:48)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.runtime.dispatcher.PrintDispatcher.firePrint(PrintDispatcher.java:27)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.PrintEngine.runJob(PrintEngine.java:44)
2008-07-02 13:15:57.108 [info] at nia.ps.engine.PrintEngine.spooler_process(PrintEngine.java:65)

Any clues friends??
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
can someone help me with this issue?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Are you using CUPS? There's a problem with CUPS changing the way they use sockets.
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
I haven't been able to solve the problem yet.I deployed my application again on a Solaris system.Using printmgr I configured a network printer on this system.Till here things are good.then when my Java application(which uses Java Print Service API) runs the call to printer seems to occur but printing(of a GIF file for example) doesn't happen.There is no error though now.
Also when I directly give the unix command
lp -d hplj file.gif it works and the gif document gets printed.
Why doesn't print call from within Java work?
I need to crack this as I am working towards production deployment but I am stuck p for qite some time because of this.
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 117

Nikhil,
Did you resolve the issue. The same happens here. Printing is done but it prints only Junk characters. Any resolution??


"Learning is a Culture where your Eagerness & Curiosity plays a major Role".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
What encoding are you using?
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 117

Hi Campbell,
I have been using the following code ..


I'm not specifically using any encoding. Just have run this class in Unix server(HP-UX). Printer is EPSON LQ-690 ESC/P2 and is connected to my Unix server. I have already raised this in http://www.coderanch.com/t/556410/java/java/Printing-data-Java-Linux-Unix
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing in Unix