Viewing PDF in Windows forms using C#

130,702

Solution 1

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

Solution 2

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

Solution 3

display PDF file into WinForms

Displaying a pdf file from Winform.

displaying a pdf on a windows form?

How to display PDF or Word's DOC/DOCX inside WinForms window?

Reading/Writing PDF Files in Visual C# Windows Forms

Solution 4

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

Share:
130,702
Majd
Author by

Majd

Updated on July 09, 2022

Comments

  • Majd
    Majd almost 2 years

    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?

  • Paul Sasik
    Paul Sasik over 13 years
    Just for viewing the IE browser control should work just fine.
  • Saif al Harthi
    Saif al Harthi over 13 years
    no he wants the windows form project he's doing hosting the reader , not launch it
  • Majd
    Majd over 13 years
    Yes, as Saif said, I need to view the pdf file inside my application and not launch the PDF reader :)
  • ArBR
    ArBR over 13 years
    Use the WebBrowser Control into your form.
  • Majd
    Majd over 13 years
    yes i think i'll go with that .. thx ..
  • thewikus
    thewikus over 10 years
    how can i resize this control so that it does not consume the whole form but stil resize when the form resizes?
  • Soumyaansh
    Soumyaansh over 7 years
    Did you able to show the pdf inside WebBrowser Control ? I am trying the same thing but the application doesn't open it inside control rather it launces the third party PDF viewer application to show the pdf.
  • V K
    V K over 7 years
    @Soumyaansh were you able to fix the issue.As, I am facing the same problem.
  • Haseeb
    Haseeb over 5 years
    1+ perfect this supposed to be answer :)
  • Stephan Stamm
    Stephan Stamm over 5 years
    I have this com component on my development machine. Does it also work on machines that do not have Adobe installed?
  • Senthi Sri
    Senthi Sri about 3 years
    It will not work on a machine that does not have Adobe PDF Reader installed. You will get "Class not Registered" exception. Related Post: stackoverflow.com/questions/4041659/…