从XPS文档中提取的单一页 [英] Extract a single page from an XPS document

查看:1075
本文介绍了从XPS文档中提取的单一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要拆分现有的XPS文档,并与原来只有一个网页创建一个新的XPS文档。我试图复制该文件,并删除复制的文档页面,但是这是非常缓慢的。有没有更有效的方法来做到这一点?在C#吧。

感谢。

解决:

 公共无效斯普利特(字符串originalDocument,串detinationDocument)
    {
        使用(包包= Package.Open(originalDocument,FileMode.Open,FileAccess.Read))
        {
            使用(包packageDest = Package.Open(detinationDocument))
            {
                字符串inMemoryPackageName =的MemoryStream://miXps.xps;
                 乌里packageUri =新的URI(inMemoryPackageName);
                 PackageStore.AddPackage(packageUri,包);
                XpsDocument xpsDocument =新XpsDocument(包,COM pressionOption.Maximum,inMemoryPackageName);
                XpsDocument xpsDocumentDest =新XpsDocument(packageDest,COM pressionOption.Normal,detinationDocument);
                固定文档序列变种= xpsDocument.GetFixedDocumentSequence();
                DocumentReference的docReference = xpsDocument.GetFixedDocumentSequence()References.First()。
                固定文档的文档= docReference.GetDocument(假);
                变种含量= doc.Pages [2];
                VAR固定页面= content.GetPageRoot(假);
                VAR writter = XpsDocument.CreateXpsDocumentWriter(xpsDocumentDest);
                writter.Write(固定页面);
                xpsDocumentDest.Close();
                xpsDocument.Close();
            }
        }
    }
 

解决方案
  1. 打开XpsDocument
  2. 创建目标XpsDocument(同样的方法)
  3. <一个href="http://msdn.microsoft.com/en-us/library/system.windows.xps.packaging.xpsdocument.getfixeddocumentsequence.aspx"相对=nofollow>从第一XpsDocument获取FixedDocumentSequece
  4. <一个href="http://stackoverflow.com/questions/3015699/get-fixeddocuments-out-of-a-fixeddocumentsequence">Get从序列的第一个固定文档。
  5. 在获得第一 PageContent Pages属性
  6. Child属性获取固定页面的PageContent的
  7. <一个href="http://msdn.microsoft.com/en-us/library/system.windows.xps.packaging.xpsdocument.createxpsdocumentwriter.aspx"相对=nofollow>从第二XpsDocument获取XpsDocumentWriter
  8. 写固定页面

容易。


正如由克里斯托弗Currens 时,可能有必要使用 PageContent.GetPageRoot 孩子中,而不是第6步。

I need to split an existing XPS Document and create a new XPS Document with only one page of the original one. I tried to copy the document and delete pages from the copied document, but that's very slow. Is there a more efficient way to do this? In C# please.

Thanks.

Resolved:

public void Split(string originalDocument, string detinationDocument)
    {
        using (Package package = Package.Open(originalDocument, FileMode.Open, FileAccess.Read))
        {
            using (Package packageDest = Package.Open(detinationDocument))
            {
                string inMemoryPackageName = "memorystream://miXps.xps";
                 Uri packageUri = new Uri(inMemoryPackageName);
                 PackageStore.AddPackage(packageUri, package);
                XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Maximum, inMemoryPackageName);
                XpsDocument xpsDocumentDest = new XpsDocument(packageDest, CompressionOption.Normal, detinationDocument);
                var fixedDocumentSequence = xpsDocument.GetFixedDocumentSequence();
                DocumentReference docReference = xpsDocument.GetFixedDocumentSequence().References.First();
                FixedDocument doc = docReference.GetDocument(false);
                var content = doc.Pages[2];
                var fixedPage = content.GetPageRoot(false);
                var writter = XpsDocument.CreateXpsDocumentWriter(xpsDocumentDest);
                writter.Write(fixedPage);
                xpsDocumentDest.Close();
                xpsDocument.Close();
            }
        }
    }

解决方案

  1. Open the XpsDocument
  2. Create the destination XpsDocument (same method)
  3. Get the FixedDocumentSequece from the first XpsDocument
  4. Get the first FixedDocument from the sequence.
  5. Get the first PageContent from the Pages property
  6. Get the FixedPage from the Child property of the PageContent
  7. Get the XpsDocumentWriter from the second XpsDocument
  8. Write the FixedPage

Easy.


As noted by Christopher Currens, it may be necessary to use PageContent.GetPageRoot instead of Child in step 6.

这篇关于从XPS文档中提取的单一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆