开发者

File opens before printing?

Hi m using this program to print my files bt it opens the file before printing?i want to remove that.any suggestions?

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class PrintFile {    

  public static void file开发者_C百科ToPrint(File fis) {
    try {
      Desktop desktop = null;
      if (Desktop.isDesktopSupported())
      {

        desktop = Desktop.getDesktop();  

      }   
       desktop.print(fis);  
       System.out.print("Printing Document");
    }
    catch (IOException ioe)
    {
      ioe.printStackTrace();
    }

  }
}


The Desktop API in AWT uses the native functionality of the system (in this case Windows.) The JVM is likely invoking ShellExecute/ShellExecuteEx on the file with the "print" command. The way Windows handles the command is to search the registry for the file type's print command, and run that. For most file types, this will result in the application that handles it opening, and then executing the print command automatically.

In short, I don't think you'll be able to use the Desktop API without having the applications open. You would need to do all the printing yourself (which, of course, is very difficult.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜