2

i have built a WPF application to view the PDF files using Interop.AcroPDFLib.dll, the problem is if the Adobe Acrobat reader is not installed on the client machine the application stops working and crashes.

Is there a way i can detect the Acrobat Reader installation before hand and then at the run time include the reference to the Interop.AcroPDFLib.dll other-wise show an error message?

OR

are there any better open source solutions available to display pdf files in WPF?

Regards.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
John x
  • 4,031
  • 8
  • 42
  • 67
  • any suggestions, ideas? please share... – John x Oct 08 '11 at 05:11
  • I'm not too familiar with COM interop, but shouldn't your application only crash when you actually *invoke* one of the methods from `Interop.AcroPDFLib.dll`? This certainly is the case for P/Invoke methods. – Christian Klauser Oct 08 '11 at 12:31

3 Answers3

1

If any app/soft. is installed in Windows, using a installer, it generally creates a entry in Installed programs seen in control panel (i.e. in registry). So you can search for it, as Adobe Reader mostly comes in a installer and check validate the installation of Adobe reader.

For reference see artice1 article2

Code0987
  • 2,598
  • 3
  • 33
  • 51
1

If any PDF capable app is properly installed then System.Diagnostics.Process.Start(@"C:\MyPDF.pdf"); start it with your PDF file...

As for detection you can check the registry at HKLM\SOFTWARE\Adobe... for the Reader and/or Acrobat.

Another option would be to check for registered file association - on how check this SO answer Script to associate an extension to a program

EDIT - as per comment:

For a scenario where you need to "dynamically" use Interop adding the reference statically is not a good idea... an alternative way is to do COM the "old-fashoined way" using something similar to the following:

object A = Activator.CreateInstance (Type.GetTypeFromProgId (""));
object R = Type.GetTypeFromProgId ("").InvokeMember ("MyMethodName", BindingFlags.InvokeMethod, null, A, new object[] {myParam1, myParam2});
Marshal.FinalReleaseComObject (A);

Relevant links:

Community
  • 1
  • 1
Yahia
  • 69,653
  • 9
  • 115
  • 144
  • tnx for the reply, can you please tell me after determining that whether Adobe Acrobat is installed or not how can i add reference to `Interop.AcroPDFLib.dll` in my project – John x Oct 08 '11 at 11:58
0

Check for GUID in component services. Usually adobe reader has the same COM GUID. Check for installation. Is it available on c:\Program Files\Adobe .... or c:\Program Files x86\Adobe.... This is assume that adobe is installed on that folder. This is the light way to do. I search for file name AcroRd32.exe using:

Directory.GetFiles(@"C:\", AcroRd32.exe", SearchOption.AllDirectories)

if it is found, then you can check that the installation of adobe reader is OK or not.

You can call adobe pdf I using Process.Start and capture its exception and then kill its process. If it is throw exception then adobe reader is not installed or corrupted. otherwise it is installed

eg:

try
{
Process.Start(@"c:\your program files\Adobe\Adobe.exe");
} catch
{
   throw new Exception ("adobe is not installed or error");
}

You can customize above code by searching adobe reader file and then passed it into Process.Start parameter.

I dunno open source solution to display pdf using wpf. sorry

nickotech2000
  • 259
  • 1
  • 7
  • 1
    -1 Sorry, this probably the worst way to do this. In the day and age of 3+TB hard drives, searching the entire disk for an executable can take minutes. Also you should be using the `%ProgramFiles%` and `ProgramFiles(x86)` environment variables. Finally the user can always choose to install Adobe in a completely different location. Instead do use the registry, that's what it was built for. – Christian Klauser Oct 08 '11 at 12:28