File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Printing directly to printer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing directly to printer" Watch "Printing directly to printer" New topic
Author

Printing directly to printer

Danny Ford
Greenhorn

Joined: Jun 01, 2008
Posts: 1
Hey guys,

I am working on a small app that chooses a file and when I click the print button it will simply print the file to the chosen printer(from the printDialog()).

I have looked at numerous tutorials and examples but most of them refer to printing components from swing or loading the file into a textarea before printing the text from that textarea.

I would like to know if there is a simple way of implementing the feature I am after and possibly some helpful code if kind enough.

I have also tried the Desktop class but opens the associated app to use its print feature.

Thank you

DP
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Welcome to JavaRanch.

Unfortunately, there is no way to "simply print a file". Java knows what to do with certain file types (e.g. text and PostScript), but in general only an application that knows what to do with a given file format can print a file (say, a web browser for an HTML file, or Adobe Reader for a PDF file). That's why the Desktop class uses the application that "owns" the file to print it.

A smart printer can help (e.g., some printers know what to do with PDFs), but generally they need something like PostScript or PCL as input, not just any file format.


Ping & DNS - updated with new look and Ping home screen widget
 
jQuery in Action, 2nd edition
 
subject: Printing directly to printer
 
Similar Threads
how to print data from a java application
Printer Functionality
printing from an applet toolbar the image displayed in the applet via a thread
java printing - printing a pdf
JeditorPane End of Page character