如何执行Windows';打印到';动词使用Java?

如何执行Windows';打印到';动词使用Java?,java,pdf,printing,Java,Pdf,Printing,在过去,我使用“printto”动词从.Net应用程序打印PDF。它看起来像这样: ProcessStartInfo psi = new ProcessStartInfo(file); psi.Verb = "printto"; // print to given printer psi.Arguments = "LPT1"; psi.CreateNoWindow = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.ErrorDi

在过去,我使用“printto”动词从.Net应用程序打印PDF。它看起来像这样:

ProcessStartInfo psi = new ProcessStartInfo(file);
psi.Verb = "printto";   // print to given printer
psi.Arguments = "LPT1";
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.ErrorDialog = true;
Process.Start(psi);
如何从Java应用程序执行此操作?还是有其他方法?请注意,目标平台将始终是Windows。

请尝试此操作

public void print() {
    //The desktop api can help calling native applications in windows
    Desktop desktop = Desktop.getDesktop();
    try {
        desktop.print(new File("yourFile.pdf"));
    } catch (IOException e) {           
        e.printStackTrace();
    }
}

请注意:这是一个简单的解决方案。您还可以使用
java的打印API
实现同样的功能

谢谢!这是可行的,但却打开了AcrobatReader,甚至更糟的是,它也打开了。你知道如何在“静默”模式下运行吗?你必须使用java的打印API来进行静默打印!请在这里通读代码