开发者

Detect the Acrobat installation or any alternate way to open PDF

开发者 https://www.devze.com 2023-04-12 02:57 出处:网络
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开发者_C百科 the application stops w

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开发者_C百科 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.


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:

  • http://msdn.microsoft.com/en-us/library/wccyzw83.aspx
  • http://msdn.microsoft.com/en-us/library/hss5hw09.aspx
  • http://msdn.microsoft.com/en-us/library/66btctbe.aspx
  • http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx
  • http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.finalreleasecomobject.aspx


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号