This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to send raw data to printer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to send raw data to printer" Watch "how to send raw data to printer" New topic

how to send raw data to printer

sushmi shrestha

Joined: Jul 06, 2008
Posts: 7
I gotta need to print some pin codes on paper directly after generating pin code. Any references of APIs in java ?

I am looking into javax.print library
Any other better alternatives?

Please help me out.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Nope. The Print Service API is the extent of your options.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

If your OS and printer supports it, you can access a printer like you would a file, like in this example from the old Java Programmer's FAQ:

[How To Ask Questions On JavaRanch]
sushmi shrestha

Joined: Jul 06, 2008
Posts: 7
Thankyou very much for helping.
I tried your code. Nothing got printed neither any errors.

I tried for the code below. The code also didn't work.

I am quite screwed up here. Neither I'm getting the expected output nor any errors are traced. I'm using network printer. Printer gets the document printed from other application but the code doesn't work leaving me no clue.

Waiting for helping hands.
Ritesh Agrawal
Ranch Hand

Joined: Jan 08, 2004
Posts: 74

Please refer to the following URL.

I tried your code and although it seems correct and same as the sample provided in the Java 6 API Docs, you need to wait for the Printing Job to be completed before closing the InputStream.

I added the code provided in the above URL, but it still didn't work for me. Thus, I added a Thread.sleep(20000); //sleep for 20 seconds to allow for Job to be completed, and then close the input stream.

Try this, hopefully it will work for you.

Ritesh<br /> <br />SCJP 1.4<br />IBM Test 340<br />IBM AIX V4.0 Certified Professional<br /> <br />Right actions for the future are the best apologies for wrong ones in the past.<br />- Tyron Edwards
Albert Kam
Ranch Hand

Joined: Oct 18, 2007
Posts: 58
Yupe, you'd have to wait.

I learned about it in the online Java Almanac 1.4 at

Here's my exerpt :

Good Luck,
Albert Kam
[ October 31, 2008: Message edited by: Albert Kam ]

Be nice !
I agree. Here's the link:
subject: how to send raw data to printer
It's not a secret anymore!