[英]VB.Net Printing PDF Fails (But equivalent works from PowerShell)
我正在嘗試編寫一個小型桌面應用程序,該應用程序可以隨處坐下來並在下載文件時打印文件。
使用PowerShell將PDF文件發送到打印機可以正常工作,並且可以打印:
.\AcroRd32.exe /N /T C:\Path\to\201402124_label.pdf "Brother QL-700"
但是,在Visual Studio 2012中執行相同操作無效。 Adobe Reader窗口打開並顯示標簽,然后關閉,但是文件從未顯示在要打印的打印機上。 這沒有任何意義,因為該相同代碼目前正以相同方式(僅使用保存在My.Settings中的另一台打印機)將較大的PDF發送至雙面打印機:
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內進行
為什么不簡單地使用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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.