Neon Neon - 1 year ago 163 Question

Check if Adobe Reader is installed before using it

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

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

Dim AcroDisplay As New AxAcroPDFLib.AxAcroPDF

AcroDisplay.Left = 50
AcroDisplay.Top = 50
AcroDisplay.Width = 200
AcroDisplay.Height = 500
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

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

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

Answer Source

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"
        If Not Array.IndexOf(AdobeSoftwares.GetSubKeyNames, "Acrobat Reader") = -1 Then
            'MessageBox.Show("Adobe Reader Installed")
            Dim PdfDisplay As New AxAcroPDFLib.AxAcroPDF
            PDFControl = "Acrobat"
            '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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download