Solved

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

Posted on 2011-03-10
8
3,786 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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 …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 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