【发布时间】:2011-11-13 17:42:47
【问题描述】:
我正在努力为我的申请提供帮助。我有我正在加载到 documentviewer 的 xps 文档。这些文件嵌入在资源文件中。
我能够以字节数组的形式访问这些。 例如 Properties.Resources.help_sudoku_methods_2 返回字节[]
但是,documentviewer 无法读取它并且需要固定的documentsequence。 所以我从bytearray创建内存流,然后是xpsdocument,然后是fixeddocumentsequence,如下所示:
private void loadDocument(byte[] sourceXPS)
{
MemoryStream ms = new MemoryStream(sourceXPS);
const string memoryName = "memorystream://ms.xps";
Uri memoryUri = new Uri(memoryName);
try
{
PackageStore.RemovePackage(memoryUri);
}
catch (Exception)
{ }
Package package = Package.Open(ms);
PackageStore.AddPackage(memoryUri, package);
XpsDocument xps = new XpsDocument(package, CompressionOption.SuperFast, memoryName);
FixedDocumentSequence fixedDocumentSequence = xps.GetFixedDocumentSequence();
doc.Document = fixedDocumentSequence;
}
这是非常不干净的方法,如果文件中有图像也不起作用 - 而不是新文档中的图像显示来自第一个加载的文档的图像。
有没有更简洁的方法将 XPS 从嵌入式资源加载到文档查看器?还是我需要一些想法,例如将文件从资源复制到应用程序目录并从这里加载而不是内存流?谢谢。
【问题讨论】:
-
其实我是在使用这篇文章来构建我的解决方案。当我有一个文件时它工作得很好,但当我一个接一个地加载一个文件时就不行了。
标签: c# .net wpf documentviewer xpsdocument