Solved

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

Posted on 2011-03-10
8
3,453 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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
 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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