• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing a text file to a printer

 
H Murdock
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have been playing around with several codes over the past couple of days and I have found nothing that will actually print a text file to the printer. First I create a regular text file that I call Print.txt. In the same method I have tried several codes to get the text file to print to a printer, but none has worked so far. I have tried code from Oracle and other Java websites but the file never seems to print. If anybody has any code suggestions it would be really helpful. I need this tonight if thats possible. Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34971
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

A servlet can't print a file. It can output javascript to open the print confirmation box as shown here
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember, a servlet executes on the server. Printers on the client are not visible to the server.
 
Tom Miller
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to clarify if you are trying to print on the server side, a printer located where your server is, or on the client side, printer located on the clients machine. You can print on the server side using LPR and a printer on the server's local network. I had a project where users would submit a form online and it would print as a filled out PDF in a processing area. There are several java implementations of the LPR protocol, google "java lpr".

If you’re trying to print on the client side you are out of luck. Best you can do is format it is html and use javascript to make the print dialog come up.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic