文件在打印前打开?
您好,我使用这个程序来打印我的文件,但它会在打印之前打开文件?我想删除它。有什么建议吗?
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class PrintFile {
public static void fileToPrint(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();
}
}
}
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 fileToPrint(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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AWT 中的桌面 API 使用系统(在本例中为 Windows)的本机功能。JVM 可能使用“print”命令在文件上调用 ShellExecute/ShellExecuteEx。 Windows 处理该命令的方式是在注册表中搜索该文件类型的打印命令,然后运行该命令。对于大多数文件类型,这将导致处理该文件的应用程序打开,然后自动执行打印命令。
简而言之,我认为在不打开应用程序的情况下您将无法使用桌面 API。您需要自己完成所有打印(当然,这非常困难。)
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.)