Solved

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

Posted on 2011-03-10
8
3,594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to find a web event on the IIS server 4 54
Can Selenium do Load Testing? 2 60
Shared Service Environment 2 54
Returning multiple values with a stored procedure 9 31
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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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