VB.Net打印PDF失败(但PowerShell的等效工作)

时间:2014-02-18 20:33:36

标签: vb.net pdf printing process

我正在尝试编写一个小型桌面应用程序,它可以随时随地打印文件。

使用PowerShell将PDF文件发送到打印机工作正常并打印:

.\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内部

1 个答案:

答案 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")