This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Want to print a file using java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Want to print a file using java program" Watch "Want to print a file using java program" New topic
Author

Want to print a file using java program

Nithin Madathil
Greenhorn

Joined: Aug 26, 2006
Posts: 11
Hi
I am looking to invoke the windows print dialog using a java program and pass a file to print when I click on the print button on the print box. Can anyone help me with a piece of code regarding this?

Nithin
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
Does your printer (or printer driver) know how to handle the file format? Otherwise, you'll have to implement printing yourself.

An introduction to printing can be found with http://java.sun.com/javase/6/docs/technotes/guides/jps/spec/jpsTitle.fm.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43970
    
  33
Or, maybe this tutorial and this one.
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
I've done that, its easy.
Nithin Madathil
Greenhorn

Joined: Aug 26, 2006
Posts: 11
Yes my printer knows the format of print data.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

But first check out java.awt.Desktop - it has a built-in print method that can print many file formats for you.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Nithin Madathil
Greenhorn

Joined: Aug 26, 2006
Posts: 11
I was trying to use SDK 1.2 Printing API Tutorial. I have invoked the print dialog but how can get a file to printer.
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192



Print to local printer using FileOutputStream
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Want to print a file using java program
 
It's not a secret anymore!