Search code examples
c#winformspdfpdfview

Viewing PDF in Windows forms using C#


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?


Solution

  • 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");