Solved

how can i view pdf file to windows form in C#.net windows application ??

Posted on 2011-03-10
8
3,207 Views
Last Modified: 2012-05-11
i want to know that how can i view pdf file to windows form in C#.net windows application ??

which control i should use ??
0
Comment
Question by:Parth48
8 Comments
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 500 total points
ID: 35094092
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);

Open in new window

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

Open in new window


0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 35094105
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35094220
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35094352
in addition to the two methods i explained there is another method  by using Adobe Acrobat as a COM reference.

To use the Reader control, first make sure that you have downloaded and installed the free Acrobat Reader from Adobe.

Step 2 is to add the control to the VB.NET Toolbox. Open VB.NET and start a standard Windows application. (Microsoft's "next generation" of presentation, WPF, doesn't work with this control yet. Sorry!) To do that, right-click on any tab (such as "Common Controls") and select "Choose Items ..." from the context menu that pops up. Select the "COM Components" tab and click the checkbox beside "Adobe PDF Reader" and click OK. You should be able to scroll down to the "Controls" tab in the Toolbox and see the "Adobe PDF Reader" there.

Now just drag the control to your Windows Form in the design window and size it appropriately.add this code to the form Load event procedure:

 private AxAcroPDFLib.AxAcroPDF axAcroPDF1;


this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();
                this.axAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.axAcroPDF1.Enabled = true;

                this.axAcroPDF1.Name = "axAcroPDF1";
                this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPDF1.OcxState")));


      axAcroPDF1.LoadFile(DownloadedFullFileName);
                        axAcroPDF1.Visible = true;

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 35094414
Just use a webBrowser control.  Then use the following code:
string path = "Your Path To The PDF";
Uri thePath = new Uri(path);
webBrowser.Url = thePath;

That will open the PDF "in" the form.
0
 

Expert Comment

by:bizbiz20032003
ID: 35094986
If Acrobate reader installed, you can launch it with this method :

        public static void StartProcess(string fileName)
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            // Name of the file to open
            proc.StartInfo.FileName = fileName;
            proc.Start();
            proc.Close(); // Close don't stop the process
        }

call :
        StartProcess(MyFilePathToPdf.PDF);
0
 

Author Comment

by:Parth48
ID: 35106075
hi @mayank_joshi: which method is better ?

can u please tell me ?
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35106153
the most convenient method is using web browser control.

i would rank the methods as follows:-

1) Web Browser Control
2) Adobe Acrobat COM reference
3) use System.Diagnostics.Process.Start

 Adobe Acrobat COM is better than  System.Diagnostics.Process.Start beacuse it displays PDF
within the application unlike the other which displays PDF as separate file using the default viewer.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS ReportViewer report timeout 7 100
Not showing page correctly 3 29
Split in Javascript 5 30
IIS issues - Convert to Application - APS.NET v4.0 3 19
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short film showing how OnPage and Connectwise integration works.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now