Solved

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

Posted on 2011-03-10
8
3,087 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
Comment Utility
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
Comment Utility
0
 
LVL 13

Expert Comment

by:agarwalrahul
Comment Utility
0
 
LVL 9

Expert Comment

by:mayank_joshi
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 15

Expert Comment

by:angus_young_acdc
Comment Utility
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
Comment Utility
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
Comment Utility
hi @mayank_joshi: which method is better ?

can u please tell me ?
0
 
LVL 9

Expert Comment

by:mayank_joshi
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

8 Experts available now in Live!

Get 1:1 Help Now