StartInfo.Verb =" PrintTo"在vb.net 2010上没有为jpg文件工作但是在pdf上工作?

时间:2015-01-25 14:54:05

标签: vb.net visual-studio-2010 printing

我正在尝试在(理论上)将jpg /图像文件打印到特定打印机的后台任何类型的文件中。

所以,我正在使用startinfo.verb =“PrintTo”

以下是使用过的代码:

    Dim objStartInfo As New ProcessStartInfo
    Dim objProcess As New System.Diagnostics.Process
    Dim sreport As String = "d:\Wallpaper\Personal Picture\xVai\DSC_0000500.jpg" but not here :(
    'Dim sreport As String = "c:\Documents and Settings\y\Desktop\x\New\requirements.pdf" rem works for pdf file
    'Dim sreport As String = "g:\My Documents\Word\Budget.doc" rem even works for document file
    Dim sPrinter As String = "Microsoft Office Document Image Writer"
    Dim iloop As Integer
    Try
        objProcess.StartInfo.CreateNoWindow = True
        objProcess.StartInfo.UseShellExecute = True
        objProcess.StartInfo.FileName = sreport
        objProcess.StartInfo.Arguments = """" & sPrinter & """"
        objProcess.StartInfo.Verb = "PrintTo"
        objProcess.StartInfo.CreateNoWindow = True
        objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        objProcess.Start()
        If objProcess.HasExited = False Then
            iloop = 0
            While Not objProcess.HasExited
                System.Threading.Thread.Sleep(100)
                iloop = CShort(iloop + 1)
                cmdProcess.Text = iloop.ToString
                Me.Refresh()
                If iloop >= 300 Then
                    Exit While
                End If
            End While
        End If
        objProcess.CloseMainWindow()
        objProcess.Close()
        objProcess.Dispose()
        objProcess = Nothing
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

它适用于doc,pdf文件但是当我尝试jpg文件时却没有。

显示错误“没有应用程序与此操作的指定文件关联”:(

我很困惑?

1 个答案:

答案 0 :(得分:1)

问题不在于您的代码,而是在您的操作系统配置中。您的Windows安装无法识别PrintTo *.jpg文件名的动词。与代码中的操作等效,您可以使用JPEG上的通用Windows资源管理器的Print操作进行测试:如果您使用它,那么它也应该在您的代码中工作。尝试在操作系统级别为PrintTo动词注册JPEG。

更多信息:Verbs and File Associations @ MSDN