我有一个通过Xps查看器查看Word和Excel文件的应用程序。我将office文件转换为xps文件,并在WPF XPS文档查看器中显示。
但是这里有一个小问题,我不希望用户看到这些文件,而是在关闭后删除这些文件。
我想知道有没有办法将xps转换成内存流,并在Xps Viewer中查看它
编辑:
我不想在磁盘上创建任何xps文件。转换过程必须在内部完成到MemoryStream。
发布于 2011-07-20 19:18:16
在poc项目中,下面的代码行对我很好,可以给您一个起点。对于文档转换部分(word/excel -> xps),您只需使用自动打印它们。
System.IO.Stream docStream = ...any xps as stream;
Package package = Package.Open(docStream);
//Create URI for Xps Package
//Any Uri will actually be fine here. It acts as a place holder for the
//Uri of the package inside of the PackageStore
string inMemoryPackageName = string.Format("memorystream://{0}.xps", Guid.NewGuid());
Uri packageUri = new Uri(inMemoryPackageName);
//Add package to PackageStore
PackageStore.AddPackage(packageUri, package);
XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum, inMemoryPackageName);
FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
// Do operations on xpsDoc here
DocViewer.Document = fixedDocumentSequence;
//Note: Please note that you must keep the Package object in PackageStore until you
//are completely done with it since certain operations on XpsDocument can trigger
//delayed resource loading from the package.
//PackageStore.RemovePackage(packageUri);
//xpsDoc.Close();发布于 2011-07-20 19:23:21
请出示一些密码..。
如果您的XPS文档被写入流中,则可以将该流传递给Package.Open,然后将包传递给XpsDocument,然后将Xpsdocument传递给DocumentViewer.这样,xps就一直保存在内存中。
例如,Aspose.Words/..Cells可以从word和Excel生成XPS到流中,因此不涉及任何文件.
https://stackoverflow.com/questions/6767192
复制相似问题