gpt4 book ai didi

c# - 从 XPS 文档中提取单个页面

转载 作者:行者123 更新时间:2023-11-30 13:50:56 27 4
gpt4 key购买 nike

我需要拆分现有的 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();
}
}
}

最佳答案

  1. Open the XpsDocument
  2. 创建目标 XpsDocument(相同方法)
  3. Get the FixedDocumentSequece from the first XpsDocument
  4. Get the first FixedDocument from the sequence.
  5. 获得第一个PageContent来自 Pages property
  6. Child property 获取 FixedPage PageContent的
  7. Get the XpsDocumentWriter from the second XpsDocument
  8. Write the FixedPage

简单。


Christopher Currens 所述,可能需要在步骤 6 中使用 PageContent.GetPageRoot 而不是 Child

关于c# - 从 XPS 文档中提取单个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5328596/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com