Check if Adobe Reader is installed before using it

2019-09-05 23:00发布

问题:

I want to be able to have my app check if Adobe Reader is installed. If it is, I want my program to use it to display the PDF, if not I want to use my free (limited) reader control to display the PDF.

Any suggestions

Edit: my question seems to be little to broad So basicly i'm trying to do the following

Try
   Dim AcroDisplay As New AxAcroPDFLib.AxAcroPDF

   AcroDisplay.Left = 50
   AcroDisplay.Top = 50
   AcroDisplay.Width = 200
   AcroDisplay.Height = 500
   me.Controls.Add(AcroDisplay)
   MsgBox("Acro Added")
Catch ex As Exception
   MsgBox("Acro Not installed")
   ''Load Alternate PDF viewer (Spire.pdf Free)
End Try

However when Acrobat Isn't installed instead of going to the catch statement it just shows an error "Could not load assembly" and then exits the sub

What i want is that if acrobat control isn't installed, that it wont display and error and instead just load the alternate pdf viewer

is there a way to check for AxAcroPDFLib.AxAcroPDF before attempting to load?

Hopefully this makes things clearer

Edit 2: After Searching and screwing around i found 2 possible ways i might be able to do this however both i can't find how to do it in VB.net

First Look for AxAcroPDFLib.AxAcroPDF in available namespaces found C# example but i don't know how to change it to Vb.net C# - How to check if namespace, class or method exists in C#??

Second Add Unhandled Exception Handler also found a few examples but none seem to work

Any Chance anyone could direct me to a working example for either (or both) of these options

回答1:

Manged to fin a working solution, doesn't work how i was originally thinking but it doe work just fine

i used the following code

    Dim AdobeSoftwares As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("ADOBE")
    If AdobeSoftwares Is Nothing Then
        'MessageBox.Show("No Adobe Software")
        Dim PdfDisplay As New PdfiumViewer.PdfViewer 
        PDFControl = "Pdfium"
    Else
        If Not Array.IndexOf(AdobeSoftwares.GetSubKeyNames, "Acrobat Reader") = -1 Then
            'MessageBox.Show("Adobe Reader Installed")
            Dim PdfDisplay As New AxAcroPDFLib.AxAcroPDF
            PDFControl = "Acrobat"
        Else
            'MessageBox.Show("Adobe Reader Not Installed")
            Dim PdfDisplay As New PdfiumViewer.PdfViewer
            PDFControl = "Pdfium"
        End If
    End If

Then in my display code i just look to see what "PDFControl" is in use and run the relevant code to display in that display

So now if adobe reader is installed, I'll be using its control, and if it isn't I'll be using the free (but less featured) control to display PDF files So hopefully if anyone else is looking at doing similar to me then they can