3

I want to show/preview local pdf files in a winforms application ()

Currently I am using Webbrowser control and tried the Navigate(uri) method but it is launching the PDF file with third party interface

Below are few highly voted answers related to the same context but unfortunately it didn't help me as the solution involves dependency of showing pdf using already installed pdf viewer in the system (Acrobat/Nirto/IE etc)

Please let me know if its possible to show the pdf without using third party packages.

Viewing PDF in Windows forms using C#

Displaying a pdf file from Winform

Community
  • 1
  • 1
Soumyaansh
  • 8,626
  • 7
  • 45
  • 45
  • so you basically want to show a pdf without having installed any viewer on your system. Do I get it right? – Mong Zhu Nov 04 '16 at 09:24
  • 1
    If it's not necessary to change the PDF document you could create an image from the file and show that. – Andre Hofmeister Nov 04 '16 at 09:35
  • @MongZhu yes you are correct ! – Soumyaansh Nov 04 '16 at 09:37
  • It seems that either you provide a reader with your application (as also already suggested by the answers that you posted) if you cannot rely on the user to have one, or you go with the image solution by @hofmeister. – Mong Zhu Nov 04 '16 at 09:52
  • Possible duplicate of [Displaying a pdf file from Winform](http://stackoverflow.com/questions/2220134/displaying-a-pdf-file-from-winform) – Bobrovsky Nov 05 '16 at 07:35

1 Answers1

2

First Method :

Use the Adobe PDF reader COM Component

  1. Navigate to the toolbox and right click to "Choose Items"
  2. Choose the "COM Components" tab
  3. Choose"Adobe PDF Reader" then click OK
  4. Drag & Drop the control to the form you want to view the PDF IN
  5. Specify the PDF file you want to read by modifing the "src" Property

Second Method :

add a WebBrowser Control into your Form and open the file by using the Navigate Method AddedwebBrowserControl.Navigate(@"c:\IntroductiontoSqlServer.pdf");

EDIT : If you dont have adobe reader installed on your machine , then the First Method will Not work for you

Yahfoufi
  • 2,220
  • 1
  • 22
  • 41
  • I guess Adobe PDF Reader COM Component requires a locale Adobe PDF Reader, right? – Andre Hofmeister Nov 04 '16 at 09:32
  • and second method will not work either as I mentioned, I want to show/preview pdf inside my application, your method will launch the pdf using third party interfaces. – Soumyaansh Nov 04 '16 at 10:08
  • The Second method will open the pdf inside the WebBrowser – Yahfoufi Nov 04 '16 at 10:23
  • @m.yahfoufi, No it wont open the pdf inside the webcontrol, It is launching the file in Acrobat, If it is happening with you then that means internally your system is using the ThirdParty PDF viewer to render the file. – Soumyaansh Nov 04 '16 at 13:09
  • I think that WebBrowser control is depending on the version of Internet Explorer installed on your machine. i have the version 11 installed. – Yahfoufi Nov 04 '16 at 13:47
  • Read this [article](https://weblog.west-wind.com/posts/2011/may/21/web-browser-control-specifying-the-ie-version). it contains some WorkAround – Yahfoufi Nov 04 '16 at 13:47