A common way of loading XpsDocument is to load it from file:

XpsDocument document = new XpsDocument(filename, FileAccess.Read, CompressionOption.NotCompressed);
FixedDocumentSequence fixedDocumentSequence = document.GetFixedDocumentSequence();
//To view in the DocViewer
docViewer.Document = fixedDocumentSequence as IDocumentPaginatorSource;

But if we need to Load the Xps from a Stream we can use the Package Class and do the following:

private void LoadXpsFromStream(Byte[] xpsByte, string packageUriString)
{
  MemoryStream xpsStream = new MemoryStream(xpsByte);
  using (Package package = Package.Open(xpsStream))
  //Remember to create URI for the package
  Uri packageUri = new Uri(packageUriString);
  //Need to add the Package to the PackageStore
  PackageStore.AddPackage(packageUri, package);
  //Create instance of XpsDocument
  XpsDocument document = new XpsDocument(package, CompressionOptions.MaximuCompression, packageUriString);
  //Do the operation on document here
  //Here I am viewing the document in the DocViewer
  FixedDocumentSequence fixedDocumentSequence = document.GetFixedDocumentSequence();
  //To view in the DocViewer
  docViewer.Document = fixedDocumentSequence as IDocumentPaginatorSource;
  //Remember to keep the Package object in PackageStore until all operations complete on document.
  //Remove the package from store
  PackageStore.RemovePackage(packageUri);
  doc.Close(); 
}

//Calling the above function from Client
//
//Get bytes[] from MemoryStream
//byte[] xpsBytes = someStream.ToArray();
//For demonstration I am reading bytes from a file
byte[] xpsBytes = File.ReadAllBytes(@"somexps.xps");
//
LoadXpsFromStream( xpsBytes, "somexps.xps");

Hope this helps.

Loading Xps from MemoryStream的更多相关文章

  1. xps 文件操作笔记

    1. 在 Silverlight 显示XPS文件,参考:http://azharthegreat.codeplex.com/ 2. Word,Excel, PPT 文件转换为XPS: 参考一(老外写的 ...

  2. 步入angularjs directive(指令)--点击按钮加入loading状态

    今天我终于鼓起勇气写自己的博客了,激动与害怕并存,希望大家能多多批评指导,如果能够帮助大家,也希望大家点个赞!! 用angularjs 工作也有段时间了,总体感觉最有挑战性的还是指令,因为没有指令的a ...

  3. 《动手实现一个网页加载进度loading》

    loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在刷新和加载的过程中为了让用户感知到 load 的过程,我们会使用一些过渡动画来表达.最常见的比如"转圈圈" ...

  4. eclipse 突然 一直在loading descriptor for XXX (XXX为工程名)Cancel Requested

    问题: eclipse 启动后,啥也不干,就一直在loading descriptor for XXX (XXX为工程名),,其他什么操作都不能操作. 如下图所示,保存文件也无法保存.  这个怎么办? ...

  5. PPT转化成Image、PPTX、XPS、EMF

    最近工作经常用到演示文稿,接触到了一款不错的免费软件—Free Spire.Presentation.使用之后发现这款软件非常轻巧,功能还挺齐全.这款软件的转化功能也是非常不错的,平时遇到的各种转换难 ...

  6. linux使用wkhtmltopdf报错error while loading shared libraries:

    官网提示 linux需要这些动态库.depends on: zlib, fontconfig, freetype, X11 libs (libX11, libXext, libXrender) 在li ...

  7. solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)

    问题描述 报如下错误,很显然,问题原因:空指针异常: ERROR (localhost-startStop-1) [   ] o.a.s.h.d.s.SolrDataImportProperties ...

  8. python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

    安装python3遇到报错: wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz ./configure --prefix=/u ...

  9. x01.os.21: print "Loading..."

    Linux Inside 是中文版,值得下载一读. 先把目标设低点,开机进入后,在屏幕上打印“Loading..."即可.由于要在 bochs 中运行,首先就是安装 bochs.Oldlin ...

随机推荐

  1. 待解决:PDF header signature not found

  2. Python tricks(2) -- method默认参数和闭包closure

    Python的method可以设置默认参数, 默认参数如果是可变的类型, 比如list, map等, 将会影响所有的该方法调用. 下面是一个简单的例子 def f(a=None, l=[]): if ...

  3. LINUX环境变量(二)

    一.Shell变量分为本地变量和环境变量. 1.本地变量:在用户现有运行的脚本中使用 a) 定义本地变量 格式: variable-name=value b) 显示本地变量 格式: set  c) 清 ...

  4. Java代码质量度量工具大阅兵

    FindBugs FindBugs, a program which uses static analysis to look for bugs in Java code. It is free so ...

  5. Jquery图片上传组件,支持多文件上传

    Jquery图片上传组件,支持多文件上传http://www.jq22.com/jquery-info230jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传.取消. ...

  6. linux平台关闭某个进程的脚本

    在开发LINUX平台下的程序时,经常需要为我们的开发的程序写启动程序和关闭程序的脚本. 启动脚本比较好做,关闭程序脚本如下: 具体思路是通过ps命令找到程序的进程ID号,然后通过Kill命令将程序Ki ...

  7. Duilib Edit编辑框禁止输入中文的方法

    转载:http://www.myexception.cn/vc-mfc/300749.html 编辑框是供用户输入的,但有时候我们要限制用户输入的内容,比如我们不让用户输入中文,只能输入字符和数字,因 ...

  8. Win32 消息响应顺序

    如果窗口处理函数响应了 WM_RBUTTONUP后,不会响应WM_CONTEXTMENU消息了.

  9. luogu3261 懒惰左偏树 [JLOI2015]城池攻占

    目录 题目 思路 错误&&反思 代码 题目 luogu 原来左偏树真的能懒惰下放 那这篇博客应该要咕咕了 一开始我按照那篇博客想了一下,感觉emm,还是瞄了一眼看到了pushdown ...

  10. POJ 2155 Matrix (二维树状数组)题解

    思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...