This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to print a file using java program

 
Nithin Madathil
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, maybe this tutorial and this one.
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done that, its easy.
 
Nithin Madathil
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes my printer knows the format of print data.
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But first check out java.awt.Desktop - it has a built-in print method that can print many file formats for you.
 
Nithin Madathil
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Print to local printer using FileOutputStream
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic