2014-02-18 37 views
0

我正在嘗試編寫一個小型桌面應用程序,它只是坐下來打印下載的文件。VB.Net打印PDF失敗(但等同於PowerShell的作品)

發送PDF文件使用PowerShell打印機工作正常,它打印:

.\AcroRd32.exe /N /T C:\Path\to\201402124_label.pdf "Brother QL-700" 

然而,做同樣的在Visual Studio 2012不起作用。 Adobe Reader窗口隨標籤打開並關閉,但文件從不在打印機上顯示。這是沒有意義的,因爲相同的代碼目前正致力於更大的PDF文件發送到相同的方式雙面打印機(只使用保存在My.Settings不同的打印機):

For Each file As IO.FileInfo In files 

    If file.CreationTime > My.Settings.LastRunDate Then 

     MsgBox(file.Name) 

     Dim startInfo As New ProcessStartInfo 
     Dim proc As Process = New Process 

     startInfo.WindowStyle = ProcessWindowStyle.Hidden 
     startInfo.Verb = "print" 
     startInfo.Arguments = My.Settings.LabelPrinterSettings.PrinterName.ToString 
     startInfo.UseShellExecute = True 
     startInfo.CreateNoWindow = True 
     startInfo.FileName = file.FullName 

     proc.StartInfo = startInfo 
     proc.Start() 

     proc.WaitForInputIdle() 
     proc.CloseMainWindow() 

    End If 

Next 

我想不通爲什麼通過CLI/PowerShell執行此操作,但不在VB.net內部

+0

另外,請添加你所說的「不工作」的意思。 –

回答

0

爲什麼不簡單地使用Process.Start(String, String)?更直接和乾淨。然後,您可以使用返回的Diagnostics.Process來運行其他命令,如WaitForInputIdle()
 

你可能會使用這樣的事:

Dim proc As Process = Process.Start("AcroRd32.exe", _ 
           String.Format("/N /T {0} ""{1}""", _ 
           "C:\Path\to\201402124_label.pdf", "Brother QL-700") 
+0

這工作很好。 – DavidScherer

+0

沒問題。玩得開心編碼。 –