如何将 XPS 文档流式传输到浏览器并将其嵌入网页中?

发布于 2024-07-06 14:35:48 字数 979 浏览 8 评论 0原文

我正在寻找一些关于如何解决这个问题的建议。 任何意见表示赞赏!

目前,我有一个 ASP.NET MVC 应用程序。 在客户端上,我有一个带有 XPS 文档 ID 的链接。 当用户单击该链接时,他们将被带到包含该文档详细信息的页面。 除了此信息之外,我还希望在同一页面中与此信息一起显示文档。

在服务器端,一旦获得 ID,我就可以从数据库中获取序列化为字节数组的文档。 问题是,将序列化文档放入网页的最佳方法是什么?

我非常希望不必将该文档放入文件系统中,然后将文件路径组合在一起。 我希望能够将文档作为“application/vnd.ms-xpsdocument”的内容类型流式传输到浏览器。

我尝试过使用 Web 控件来处理这个问题(无法写出二进制文件),考虑创建一个 HTTP 处理程序来执行此操作(不知道从哪里开始),并且尝试了其他几种获取文档的方法流到浏览器。

另外,还有如何将文档嵌入到网页中的问题。 我是否使用 EMBED 标签? 还是一个对象? 或者我是否使用 iframe 并将源设置为指向提供文档的任何内容?

再说一次,我不希望有一个简单的解决方案。 我正在寻找一些关于如何解决这个问题的建议。 而且,虽然这个问题与 xps 文档有关,但它适用于流式传输要在浏览器中托管的二进制文件(PDF 等)的任何应用程序。


好吧,至于在浏览器中显示,一个字:Silverlight。 就这样解决了。 我仍然存在找出将其从服务器发送到浏览器的最佳方法的问题。


打击那个。 看来 Silverlight 还不够先进,不足以显示 XPS 文档。 我现在正在考虑一个指向 http 处理程序的 iframe...iframe 可以工作。 太糟糕了,它把整个事情都扔进了管道。 我想我总是可以剥掉第一页并发送那只小狗......


哇。 不需要 HTTP 处理程序。 MVC 中的自定义 ActionResult 就足够了。 那有多棒?

I'm looking for some suggestions on how to go about this. Any input is appreciated!

Currently, I have an ASP.NET MVC application. On the client, I have a link with an ID of an XPS document. When the user clicks the link, they are taken to a page with details about the document. In addition to this information, I wish to display the document along side of this information, in the same page.

On the server side, once I have the ID, I can get the document, serialized as a byte array, from the database. The question is, what's the best way to get that serialized document into the webpage?

I would SEVERELY prefer not having to drop that document into the file system and then munge together a file path. I would like to be able to stream the document to the browser as a content type of "application/vnd.ms-xpsdocument".

I've tried using a web control to handle this (can't write binary out), thought about creating a HTTP handler to do this (no idea where to start), and have fuddled around with a couple other ways to get the document stream to the browser.

In addition, there is also the question of how to embed the document in the web page. Do I use an EMBED tag? Or an Object? Or do I use an iframe and set the source to point to whatever delivers the document?

Again, I don't expect a solution wrapped up in a bow. I'm looking for some advice on how to go about this. And, while this question is about xps documents, it applies to any application that streams a binary file that is to be hosted in a browser (PDFs, etc).


Okay, as for displaying in the browser, one word: Silverlight. That's solved. I still have the issue of figuring out the best way to send it from the server to the browser.


Strike that. It appears Silverlight isn't advanced enough to display an XPS document just quite yet. I'm thinking about an iframe pointing to a http handler now... The iframe works. Too bad it throws the entire thing down the pipe. I suppose I could always strip off the first page and send that puppy...


Wow. No need for a HTTP handler. A custom ActionResult in MVC is all you need. How friggen awesome is that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2024-07-13 14:35:49

我认为最简单的方法是从详细信息页面提供文档作为链接 (target="_blank")。 这有几个优点:

  • 除非用户要求,否则您不需要检索和流式传输整个文档。
  • 在我的系统上,至少 IE 已经注册为默认 XPS 查看器,因此通过为文档提供它自己的窗口,您可以避免如何嵌入它的整个问题。
  • 它使得为文档提供流式源变得简单:只需使用带有查询字符串参数 ID 的 HTTP 处理程序即可。

即使您不喜欢这个想法,也一定要使用 HTTP 处理程序来传输文档。 做起来非常简单:当您在 Visual Studio 中创建一个新的 HTTP 处理程序时,它应该为您提供一个漂亮的页面,其中所有繁忙的工作都已完成。

I think the simplest way would be to provide the document as a link (target="_blank") from the details page. This has several advantages:

  • You don't need to retrieve and stream the entire doc unless the user asks for it.
  • On my system at least IE is already registered as the default XPS viewer, so by giving the doc it's own window you avoid the whole question of how to embed it.
  • It makes it simple to provide a streaming source for the document: just use an HTTP Handler with an ID for a query string parameter.

Even if you don't like that idea, definitely go with an HTTP Handler for transmitting document. It's real simple to do: when you create a new HTTP Handler in Visual Studio it should give you a nice page with all the busy-work done already.

逐鹿 2024-07-13 14:35:49

有一个能够显示 XPS 文档的 Silverlight 控件。 请参阅 http://firstfloorsoftware.com/blog/announcement-document-toolkit- for-silverlight/ 了解更多

There is a Silverlight control capable of displaying XPS documents. See http://firstfloorsoftware.com/blog/announcement-document-toolkit-for-silverlight/ for more

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文