在WPF应用程序中显示PDF

时间:2020-03-05 18:51:01  来源:igfitidea点击:

有什么想法如何在WPF Windows应用程序中显示PDF文件吗?

我正在使用以下代码运行浏览器,但是Browser.Navigate方法没有任何作用!

WebBrowser browser = new WebBrowser();
browser.Navigate("http://www.google.com");
this.AddChild(browser); // this is the System.Windows.Window

解决方案

回答

检查一下:http://itextsharp.sourceforge.net/
我们可能必须使用WindowsFormsHost,但是由于它是开源的,因此我们可以在WPF中使其更加优雅。

回答

我们可以简单地在表单上托管一个Web浏览器控件,然后使用它来打开PDF。

.NET 3.51中有一个新的本地WPF" WebBrowser"控件,或者我们可以在WPF应用程序中托管Windows.Forms浏览器。

回答

哎呀。这是用于winforms应用程序。不适合WPF。无论如何,我都会发布。

试试这个

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;

回答

以下代码要求安装Adobe Reader,并将Pdf扩展名与此连接。
它只是运行它:

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

回答

我们可以使用WindowsFormHost控件使Acrobat Reader控件在WPF应用程序中工作。我在这里有一篇关于它的博客文章:

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

我还有一个5分钟的截屏视频,介绍了我在这里的制作过程:

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