2014-02-26 26 views
1

在过去,我使用'printto'动词通过.Net应用程序打印PDF文件。它看起来像这样:如何使用Java执行Windows'printto'动词?

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。

回答

2

请试试这个。

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's Print API实现同样的事情

+0

谢谢!这有效,但打开AcrobatReader并且 - 更糟糕的是 - 将其打开。任何想法如何使这个运行在'沉默'模式? – paul

+0

您将不得不使用java的打印API来进行无声打印! – ItachiUchiha

+0

请通过这里的代码http://www.java-forum.org/allgemeine-java-themen/99423-pdf-itext-drucken.html – ItachiUchiha