如何使用MVVM显示pdf文件 [英] How to display pdf file using MVVM

查看:154
本文介绍了如何使用MVVM显示pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用mvvm在我的WPF应用程序中显示Pdf文件



我尝试过:



我想在我的WPF应用程序中使用mvvm显示Pdf文件

解决方案

WPF无法显示PDF文件它自己的。您必须使用第三方控件才能执行此操作。只是谷歌在wpf应用程序中显示pdf,你会得到大量的例子。


你不能保证按照定义显示PDF文件。 PDF不是W3标准的一部分;如果从未通过网络标准化,我会很高兴;它的概念对Web来说非常陌生。它没有任何问题:内容类型是标准化的。您只需要通过服务器端生成的HTML代码片段提供文件,例如

< a href =   yourPdfFile.pdf>您的PDF文件< /   a  >  



为此,您需要将此文件放在服务器端,文件系统中,或动态创建此类文件。这并不总是可以接受的。您还可以动态生成PDF内容,使其成为返回HTTP响应中内容的ASP.NET页面。为此,您的服务器端代码应在 HTTPResponse 中生成内容,并编写适当的 content-type 标头,内容类型为application / PDF格式。请参阅:

HttpResponse Class (System.Web)

HttpResponse.ContentType属性(System.Web)

媒体类型(IANA支持所有媒体类型的标准)。



这是一组PDF参考您可以使用的库: http://csharp-source.net/open-source/pdf-libraries





以下是它的工作原理:



你不能假设客户端计算机上安装了支持PDF的任何内容。客户端可以在浏览器中启用PDF插件,然后它将显示在浏览器窗口中。如果没有,用户将可以选择在默认的PDF查看器中打开PDF。这样的观众可能存在也可能不存在;如果没有,用户可以选择在本地保存文件并在以后打开它;用于打开文件的软件也可能存在,也可能不存在,但这不是问题而不是您的问题。



-SA

I Want to display the Pdf file in my WPF Application using mvvm

What I have tried:

I Want to display the Pdf file in my WPF Application using mvvm

解决方案

WPF has no facility to display a PDF file on it's own. You have to use a 3rd party control to do it. Just Google for "show pdf in wpf application" and you'll come up with a ton of examples.


You cannot guarantee to display PDF file, by definition. PDF is not a part of W3 standards; and I would be glad if it never become standardized with the Web; it's concept is very foreign to Web. It does not present any problems: the content type is standardized. You just need to provide the file by the fragment of HTML code generated on your server side, such as

<a href="yourPdfFile.pdf">Your PDF file</a>


To do so, you would need to have this file on your server side, in a file system, or create such file dynamically. This is not always acceptable. You can also generate PDF content on the fly, make it an ASP.NET page returning the content in HTTP response. To do so, your server-side code should generate the content in HTTPResponse and write appropriate content-type header, with the content type "application/pdf". Please see:
HttpResponse Class (System.Web),
HttpResponse.ContentType Property (System.Web),
Media Types (IANA supports the standard for all media types).

This is a set of references to PDF libraries you can use: http://csharp-source.net/open-source/pdf-libraries.


Here is how it will work:

You cannot assume that anything supporting PDF is installed on the client machine. The client can have PDF plug-in enabled in the browser, then it will be shown in the browser window. If not, the user will be given a choice to open the PDF in a default PDF viewer. Such viewer may or may not exist; if not, the user will have a choice to save the file locally and open it later; the software for opening the file also may or may not exist, but this is not a problem and not your concern.

—SA


这篇关于如何使用MVVM显示pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆