【问题标题】:Extract a single page from an XPS document从 XPS 文档中提取单个页面
【发布时间】: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


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

    简单。


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

    【讨论】:

    • 我无法从具有多个 XPS 文件的 PageContentChild 属性中获取 FixedPage 的任何内容。当通过Source属性设置固定页面时,第6步需要使用PageContent.GetPageRoot而不是Child。在MSDN文档中,但我一直忽略它。
    • @ChristopherCurrens 感谢您提供的信息。添加到问题中。
    【解决方案2】:

    谢谢,它可以帮助很多人寻找解决 Xps 打印限制的解决方法,该限制忽略了在页面级别定义的 PrintTicket。

    https://connect.microsoft.com/VisualStudio/feedback/details/529120/printqueue-addjob-ignores-printtickets-in-xps-documents

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-29
      • 2015-11-04
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多