【发布时间】:2011-07-16 18:17:27
【问题描述】:
我需要拆分现有的 XPS 文档并创建一个新的 XPS 文档,其中只有原始页面的一页。我试图复制文档并从复制的文档中删除页面,但这很慢。有没有更有效的方法来做到这一点?请在 C# 中。
谢谢。
已解决:
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();
}
}
}
【问题讨论】:
标签: c# .net xps xps-generation