• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Printing to a document

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you ever get an answer to your last question?
 
Marshal
Posts: 76870
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Always look on the bright side of life. At least this ad is really tiny:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic