How can I use a servlet to print a file on a printer attached to the server?

Serge Knystautas

This depends on how your printers are attached to your computer. I can think of two basic ways you can print to a printer attached to the server.

One approach is to create a java.awt.Frame, and then use java.awt.Toolkit's getPrintJob method to print that Frame to the printer. This will return a java.awt.PrintJob object if it works.

The second approach is more OS specific. You could create a temporary file and copy that file to the printer device. This would allow you more flexibility and ease in terms of what you could print, but would tie you into how your OS provided printer devices.

[See also http://www.jguru.com/jguru/faq/view.jsp?EID=98857]