aspose file tools*
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
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
Author

how to send raw data to printer

sushmi shrestha
Greenhorn

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
Bartender

Joined: Apr 14, 2004
Posts: 10336

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


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

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:



"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
sushmi shrestha
Greenhorn

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
Hi,

Please refer to the following URL.

http://www.tek-tips.com/viewthread.cfm?qid=1126898&page=1

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 http://www.exampledepot.com/egs/javax.print/WaitForDone.html?l=rel

Here's my exerpt :



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

Be nice !
 
Consider Paul's rocket mass heater.
 
subject: how to send raw data to printer