Hi,
Any ideas how to open a PDF file in a WPF Windows Application?
Hi,
Any ideas how to open a PDF file in a WPF Windows Application?
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.
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.
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
Tried the following code but nothing happens:
string path = @"c:\something\foo.pdf";
AcroPDFLib.AcroPDFClass pdf = new AcroPDFLib.AcroPDFClass();
bool isLoaded = pdf.LoadFile(path);
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;
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)
{
}
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.
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
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:
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?