2014-02-26 35 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