Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Head First Android this week in the Android forum!
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: 42956
    
  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: 43368
    
  32
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: 20049
    
  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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Want to print a file using java program
 
It's not a secret anymore!