• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing to a document  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I have a text file that I need to print to paper using java. I don't mean System.out.println() Has anyone got some sample code I could use for this? I normally read my way into this but I'm in a bit of a rush with this.

Thanks
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The tutorial: http://java.sun.com/docs/books/tutorial/2d/printing/

Some code examples: http://www.exampledepot.com/egs/javax.print/pkg.html

Everything else: http://java.sun.com/javase/technologies/desktop/printing/
 
Sheriff
Posts: 21288
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the java.awt.print and javax.print packages, and this.
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help. It doesn't seem to work or I'm doing something wrong.

My code is as follows:


For some reason "PrintService service = PrintServiceLookup.lookupDefaultPrintService();" is causing an issue. service gets a null value at this point. How can I resolve this?

EDIT: Not using it as an applet so it is not the security settings

Thanks
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd guess that no printer is attached that can handle INPUT_STREAM.TEXT_PLAIN_UTF_16.

Example e703 shows how to list all print services that are available; that'd be a good starting point for more investigation.
 
Robin Heard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everthing seems to work on javas end now but when trying to print I get the following error message in the status windows of the printer queue: Error: pstopdffilter/pstocupsraster failed with err number -31000

I'm using the following stream:


I have tried several different ones such as text UTF 16 and postscript but that had no affect. Does anyone know what this error message means?

Thanks
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever get an answer to your last question?
 
Marshal
Posts: 58295
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tom McCobb wrote:Did you ever get an answer to your last question?

Not here, by the looks of it Try contacting him with the "PM" button on the previous message, and see whether he is able to help.

Welcome to the Ranch, anyway
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!