Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从XPS文档中提取单个页面_C#_.net_Xps_Xps Generation - Fatal编程技术网

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

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

我需要拆分一个现有XPS文档,并创建一个新的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();
            }
        }
    }
  • 创建目标XpsDocument(相同方法)
  • 从第一个
  • 从页面内容的
  • 简单



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

    谢谢,它可以帮助许多人找到一种解决Xps打印限制的方法,Xps打印会忽略在页面级别定义的打印票证


    我在从带有多个XPS文件的
    PageContent
    Child
    属性获取FixedPage时遇到问题。当固定页面由Source属性设置时,对于步骤6,您需要使用
    PageContent.GetPageRoot
    而不是
    Child
    。它在MSDN文档中,但我一直忽略它。@ChristopherCurrens谢谢你提供的信息。补充问题。