从XPS文档中提取的单一页 [英] Extract a single page from an XPS document
本文介绍了从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();
}
}
}
解决方案
- 打开XpsDocument
- 创建目标XpsDocument(同样的方法)
- <一个href="http://msdn.microsoft.com/en-us/library/system.windows.xps.packaging.xpsdocument.getfixeddocumentsequence.aspx"相对=nofollow>从第一XpsDocument获取FixedDocumentSequece
- <一个href="http://stackoverflow.com/questions/3015699/get-fixeddocuments-out-of-a-fixeddocumentsequence">Get从序列的第一个固定文档。
- 在获得第一 PageContent 从 Pages属性
- 从 Child属性获取固定页面的PageContent的
- <一个href="http://msdn.microsoft.com/en-us/library/system.windows.xps.packaging.xpsdocument.createxpsdocumentwriter.aspx"相对=nofollow>从第二XpsDocument获取XpsDocumentWriter
- 写固定页面
容易。
正如由克里斯托弗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();
}
}
}
解决方案
- Open the XpsDocument
- Create the destination XpsDocument (same method)
- Get the FixedDocumentSequece from the first XpsDocument
- Get the first FixedDocument from the sequence.
- Get the first PageContent from the Pages property
- Get the FixedPage from the Child property of the PageContent
- Get the XpsDocumentWriter from the second XpsDocument
- 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屋!
查看全文