C# 如何在 WinForms 窗口中显示 PDF 或 Word 的 DOC/DOCX?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/511046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:15:34  来源:igfitidea点击:

How to display PDF or Word's DOC/DOCX inside WinForms window?

c#winformsms-word

提问by tomo

I'm wondering what's the best option to display a pdf/doc document inside form in my c# winforms app.

我想知道在我的 c# winforms 应用程序中在表单内显示 pdf/doc 文档的最佳选择是什么。

This control should only allow do display preview. Edtiting documents should be forbidden.

这个控件应该只允许显示预览。应禁止编辑文件。

I'm looking for free solution.

我正在寻找免费的解决方案。

The best option would be to attach a few separate *.dlls to solution but it's not a requirement.

最好的选择是将几个单独的 *.dll 附加到解决方案中,但这不是必需的。

采纳答案by David Morton

I wrote something that can do this for Word Documents by taking advantage of the WebBrowser control for WinForms. Hopefully it might do you some good:

我通过利用 WinForms 的 WebBrowser 控件编写了一些可以为 Word 文档执行此操作的内容。希望它可能对你有好处:

http://codinglight.blogspot.com/2008/10/simple-docbrowser-control.html

http://codinglight.blogspot.com/2008/10/simple-docbrowser-control.html

回答by dajood

An often suggested solution is to use a webbrowser component inside the form that views the PDF: MSDN

通常建议的解决方案是在查看 PDF 的表单中使用 webbrowser 组件: MSDN

Another approach is to use an ActiveX Control included with the Adobe Acrobat Reader but therefore you need a license from Adobe.

另一种方法是使用包含在 Adob​​e Acrobat Reader 中的 ActiveX 控件,但因此您需要来自 Adob​​e 的许可。

回答by Jonathan C Dickinson

You can use Preview Handlers. There is a WPF Articleover at CodeProject, which should be dead easy to translate to WinForms if you need it.

您可以使用预览处理程序。CodeProject 上有一篇WPF 文章,如果您需要,它应该很容易转换为 WinForms。

回答by ptilton

Consider using the preview handlers for Vista, Windows 7. I used the code provided by Brad Smith (with corrections from the comments).

考虑使用 Vista 和 Windows 7 的预览处理程序。我使用了 Brad Smith 提供的代码(根据评论进行了更正)。

http://www.brad-smith.info/blog/archives/79- Hosting Preview Handlers in Windows Forms Applications

http://www.brad-smith.info/blog/archives/79- 在 Windows 窗体应用程序中托管预览处理程序