tags:

views:

10300

answers:

12

Hi,

Any ideas how to open a PDF file in a WPF Windows Application?

A: 

Check this out: http://itextsharp.sourceforge.net/ You may have to use a WindowsFormsHost, but since it is open source, you might be able to make it a little more elegant in WPF.

Geoffrey Chetwood
A: 

You could simply host a Web Browser control on the form and use it to open the PDF.

There's a new native WPF "WebBrowser" control in .NET 3.51, or you could host the Windows.Forms browser in your WPF app.

Guy Starbuck
A: 

Do you want to display the PDF in WPF?

Aaron Fischer
A: 

I am using the following code to run the browser but the Browser.Navigate method does not do anything!

 WebBrowser browser = new WebBrowser();
            browser.Navigate("http://www.google.com");

            this.AddChild(browser); // this is the System.Windows.Window
azamsharp
A: 

Ohh by the way the PDF is located on a client's computer.

azamsharp
A: 

Tried the following code but nothing happens:

 string path = @"c:\something\foo.pdf";

                AcroPDFLib.AcroPDFClass pdf = new AcroPDFLib.AcroPDFClass();
                bool isLoaded = pdf.LoadFile(path);
azamsharp
+2  A: 

Oops. this is for a winforms app. Not for WPF. I will post this anyway.

try this

    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;
Gulzar
A: 

Nopes noting is happening:

   try
            {
                AxAcroPDFLib.AxAcroPDF axAcroPDF1;

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

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


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

            }
            catch(Exception ex)
            {

            }
azamsharp
A: 

I got it working using the WinForms but not WPF. I guess I will fire away the WinForm from the WPF and use the Adobe Reader Control to read the PDF.

azamsharp
A: 

Following expects Adobe Reader to be installed. And the Pdf extension to be connected to this. It simply runs it.

String fileName = "FileName.pdf"; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = fileName; process.Start(); process.WaitForExit();

Greetings, Eric Gehring, www.softex.nl

+6  A: 

You can get the Acrobat Reader control working in a WPF app by using the WindowsFormHost control. I have a blog post about it here:

http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/

I also have a 5 minute screencast of how I made it here:

http://www.screencast.com/t/JXRhGvzvB

A: 

You can get the Acrobat Reader control working in a WPF app by using the WindowsFormHost control. I have a blog post about it here:

I also have a 5 minute screencast of how I made it here:

This works great!!! Thanks! Now all I need to do is figure out how to load the file from a SQL Database! Any ideas?

Chris