如何使用 XPSDocument 打开 WPF 应用程序中作为二进制资源包含的 XPS 文件?
基本上,我已将 xps 文件嵌入到包含 XPSDocument Viewer 作为资源的 WPF 应用程序中。
加载应用程序时,我只希望文档查看器显示该嵌入资源。
public Page1()
{
InitializeComponent();
XpsDocument doc = new XpsDocument(SmartsysBrowser.Properties.Resources.test1, FileAccess.Read);
docViewer.Document = doc.GetFixedDocumentSequence();
docViewer.Focus();
}
但是这个命令没有通过要求
XpsDocument doc = new XpsDocument(SmartsysBrowser.Properties.Resources.test1, FileAccess.Read);
我知道我需要输入 XPS 文档的文件路径,但由于它是作为资源嵌入的,该怎么办?
非常感谢大家。
背景: 我应该制作一个显示机密文档的应用程序,并且由于限制其副本的制作/打印/分发也很重要,因此我决定使用 ClickOnce WPF XBAP 应用程序。我的推理是,一旦我从网络服务器中删除应用程序,ClickOnce 应用程序的所有副本都会变得无用。此外,这似乎是保护机密文件最便宜、最可行的方法。请随时提出替代方案。我总是热衷于向你们所有人学习。
Basically I have embedded a xps file in a WPF application containing a XPSDocument Viewer as a resource.
On loading the application, I just want the document viewer to display that embedded resource.
public Page1()
{
InitializeComponent();
XpsDocument doc = new XpsDocument(SmartsysBrowser.Properties.Resources.test1, FileAccess.Read);
docViewer.Document = doc.GetFixedDocumentSequence();
docViewer.Focus();
}
however this command does not pass muster
XpsDocument doc = new XpsDocument(SmartsysBrowser.Properties.Resources.test1, FileAccess.Read);
I do know that I need to type the filepath of the XPS document but since it is embedded as a resource, how to?
Thanks very much all.
Background:
I am supposed to make a application that will display a confidential document and since it is also important to restrict copies of it being made/printed/circulated, I have decided a ClickOnce WPF XBAP application is the way to go. My reasoning, all copies of a ClickOnce application can be rendered useless once I remove the application from the webserver. Furthermore, it seems to be the cheapest and most viable way to protect a confidential document. Please do feel free to suggest alternatives. I am always keen to learn from you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用嵌入式资源(即非 WPF 资源)时,您可以使用 Assembly.GetManifestResourceStream 从资源名称中获取 Stream,然后使用静态 Package.Open 获取 Package 实例,然后您可以使用其他 XpsDocument接受 Package 作为参数的构造函数。
As you're using embedded resources (i.e. non-WPF resource), you could use Assembly.GetManifestResourceStream to get a Stream from your resource name, then use the static Package.Open to get a Package instance, then you can use the other XpsDocument constructor that accepts a Package as parameter.