简体   繁体   中英

Is it possible to pop up print dialogue while printing a document from java?

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);
} 

您是否尝试过使用Desktop#print(File file)方法?

Try the Java print service API.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM