42

Is there any way to view PDF files in a Winforms tool? I've seen solutions such as converting the pdf file into images and showing them in an picture box. However, I am asking whether i can view the file as PDF. Is there any tool from adobe or from Microsoft that supports this?

Majd
  • 1,358
  • 3
  • 15
  • 29
  • 2
    Not all end-user computers will have Adobe Reader or some other PDF viewer (with a IE plugin) installed. So, you will need a native .NET control to display the PDF. Gnostice has a [PDF viewer control for .NET](http://www.gnostice.com/nl_article.asp?id=159&t=How_To_Create_A_PDF_Viewer_in_PDFOne_NET_v2_x "PDF viewer control for .NET") in the PDFOne component suite. Disclaimer: I work for this company. – BZ1 Jan 05 '11 at 08:48
  • interesting!! i already finished the project i was working on when i asked this question .. but i'm gonna try this for sure!! thx for the tip ;) – Majd Jan 07 '11 at 23:25
  • This was answered in an WPF question so I don't know if it works, but it is for winforms... http://stackoverflow.com/questions/55083/opening-a-pdf-in-wpf-application/55177#55177 – LD7 Dec 21 '10 at 22:17

5 Answers5

31

i think the easiest way is to use the Adobe PDF reader COM Component

  1. right click on your toolbox & select "Choose Items"
  2. Select the "COM Components" tab
  3. Select "Adobe PDF Reader" then click ok
  4. Drag & Drop the control on your form & modify the "src" Property to the PDF files you want to read

i hope this helps

Saif al Harthi
  • 2,948
  • 1
  • 21
  • 26
  • how can i resize this control so that it does not consume the whole form but stil resize when the form resizes? – thewikus Nov 21 '13 at 10:21
  • 1+ perfect this supposed to be answer :) – Haseeb Dec 14 '18 at 22:48
  • 1
    I have this com component on my development machine. Does it also work on machines that do not have Adobe installed? – Stephan Stamm Feb 15 '19 at 12:10
  • 1
    It will not work on a machine that does not have Adobe PDF Reader installed. You will get "Class not Registered" exception. Related Post: https://stackoverflow.com/questions/4041659/comexception-0x80040154-class-not-registered-when-using-axacropdflib/17894788 – Senthi Sri Jun 25 '21 at 18:41
31

you can use System.Diagnostics.Process.Start as well as WIN32 ShellExecute function by means of interop, for opening PDF files using the default viewer:

System.Diagnostics.Process.Start("SOMEAPP.EXE","Path/SomeFile.Ext");

[System.Runtime.InteropServices.DllImport("shell32. dll")]
private static extern long ShellExecute(Int32 hWnd, string lpOperation, 
                                    string lpFile, string lpParameters, 
                                        string lpDirectory, long nShowCmd);

Another approach is to place a WebBrowser Control into your Form and then use the Navigate method for opening the PDF file:

ThewebBrowserControl.Navigate(@"c:\the_file.pdf");
ArBR
  • 4,032
  • 2
  • 23
  • 29
3

Web Browser control might work. http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx

Also a bunch of pdf open source c# projects here http://csharp-source.net/open-source/pdf-libraries

madmik3
  • 6,975
  • 3
  • 38
  • 60
0

http://www.youtube.com/watch?v=a59LvC6BOuk

Use the above link

private void btnopen_Click(object sender, EventArgs e){
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK){
        axAcroPDF1.src = openFileDialog1.FileName;
    }
}
joakimbl
  • 18,081
  • 5
  • 54
  • 53