0

I have to print a word document from java. I could just open it and print it. But the following code print it automatically. Is there any way to pop up a print dialogue to choose printer? If the user does not wish to print it, he should be possible to cancel it. Also I need to close the word after printing. Please help me.

public static void main(String args[]) throws IOException {
   Desktop desktop = Desktop.getDesktop();
   File f = new File("C:\\Users\\asa\\Desktop\\resume.doc");
   desktop.open(f);
   Thread.sleep(5000);          
   desktop.print(f);
} 
skmaran.nr.iras
  • 8,152
  • 28
  • 81
  • 116
  • 1
    http://stackoverflow.com/questions/7336340/how-to-print-excel-file-and-word-document-in-java – PeterMmm Jul 18 '12 at 10:28
  • 1
    Read this: http://stackoverflow.com/questions/2446721/how-to-get-print-out-of-a-ms-word-file-from-java-application?rq=1 – lbalazscs Jul 18 '12 at 10:29

2 Answers2

3

Have you tried using Desktop#print(File file) method?

ioreskovic
  • 5,531
  • 5
  • 39
  • 70
1

Try the Java print service API.

Tutorial here: http://docs.oracle.com/javase/tutorial/2d/printing/services.html

Lucas Arrefelt
  • 3,879
  • 5
  • 41
  • 71