【问题标题】:StartInfo.Verb = "PrintTo" on vb.net 2010 not working for jpg file but work on pdf?StartInfo.Verb = vb.net 2010 上的“PrintTo”不适用于 jpg 文件但适用于 pdf?
【发布时间】:2015-01-25 14:54:04
【问题描述】:

我正在尝试在特定打印机的背景中(理论上)以任何类型的文件打印 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 文件时,它就不行了。

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

我很困惑?

【问题讨论】:

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


    【解决方案1】:

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

    更多信息:Verbs and File Associations @ MSDN

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2011-03-09
      • 2012-08-04
      • 1970-01-01
      • 2013-08-24
      相关资源
      最近更新 更多