【问题标题】:How to start an Adobe Reader or Acrobat from VB.NET?如何从 VB.NET 启动 Adob​​e Reader 或 Acrobat?
【发布时间】:2014-09-12 12:24:09
【问题描述】:

在 Windows 资源管理器中,双击 PDF 可在 Adob​​e Reader 中打开该文档。完美的!

但我的 Winforms 应用程序中的 PROCESS.START(pdfdocumentpath) 在 IE 中打开 PDF。是否存在允许 PROCESS.START(或其他 VB.NET 代码)以与 Windows 资源管理器相同的方式打开文档的设置?

我的一些用户有 32 位机器,一些有 64 位机器。有些有 Adob​​e Reader,有些有 Adob​​e Acrobat。有些可能是一个版本或更多版本,有些将是最新的。有些将产品放在其标准位置,有些可能已将它们安装在其他位置。

我想要做的是在 Adob​​e Reader 中打开文档(如果有的话)和 Adob​​e Acrobat(如果有的话)。

我怎样才能做到这一点?

【问题讨论】:

  • 什么不使用提供的控件可以做到这一点?

标签: vb.net pdf adobe


【解决方案1】:

为此使用 try catch。
而且您并不总是需要提供路径。“某些程序可以仅以名称开头”

Adobe acrobat = acrobat
Acrobat 阅读器 = AcroRd32
视觉工作室 = devenv
以此类推

现在看代码:)

首先使用 If My.Computer.FileSystem.FileExists(FilePath) Then 检查文件是否存在
如果文件存在,请尝试。"If not MsgBox("File not found.")"

所以首先尝试打开 Adob​​e Acrobat "Process.Start("acrobat", FilePath)"
如果这不起作用,请再次尝试捕获。
所以现在尝试打开 acrobat reader。"Process.Start("AcroRd32", FilePath)"
如果这不起作用,请再次使用 catch 做另一次尝试。
但现在只需使用“Process.Start(FilePath)”。
因此,在最后一次捕获中,您告诉用户安装 acrobat reader。 :)

Dim FilePath As String = "C:\Test.pdf"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    If My.Computer.FileSystem.FileExists(FilePath) Then
        Try
            Process.Start("acrobat", FilePath)
        Catch ex As Exception
            Try
                Process.Start("AcroRd32", FilePath)
            Catch ex2 As Exception
                Try
                    Process.Start(FilePath)
                Catch ex3 As Exception
                    MsgBox("Instal Acrobat Reader")
                End Try
            End Try
        End Try
    Else
        MsgBox("File not found.")
    End If

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多