C# 从XPS文档中提取单个页面
我需要拆分一个现有XPS文档,并创建一个新的XPS文档,其中只包含原始XPS文档的一页。我试图复制文档并从复制的文档中删除页面,但速度非常慢。有没有更有效的方法?请用C 谢谢 决议:C# 从XPS文档中提取单个页面,c#,.net,xps,xps-generation,C#,.net,Xps,Xps Generation,我需要拆分一个现有XPS文档,并创建一个新的XPS文档,其中只包含原始XPS文档的一页。我试图复制文档并从复制的文档中删除页面,但速度非常慢。有没有更有效的方法?请用C 谢谢 决议: public void Split(string originalDocument, string detinationDocument) { using (Package package = Package.Open(originalDocument, FileMode.Open, Fil
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();
}
}
}
如所述,可能需要在步骤6中使用
PageContent.GetPageRoot
而不是Child
。谢谢,它可以帮助许多人找到一种解决Xps打印限制的方法,Xps打印会忽略在页面级别定义的打印票证
我在从带有多个XPS文件的
PageContent
的Child
属性获取FixedPage时遇到问题。当固定页面由Source属性设置时,对于步骤6,您需要使用PageContent.GetPageRoot
而不是Child
。它在MSDN文档中,但我一直忽略它。@ChristopherCurrens谢谢你提供的信息。补充问题。