Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:29:26+00:00 2026-06-07T16:29:26+00:00

I have problem when merging multiple XPS documents into one. When I merge them,

  • 0

I have problem when merging multiple XPS documents into one. When I merge them, the result xps contains last XPS document that duplicated. Here is my function to merge (Modified version of this question):

    public XpsDocument CreateXPSStream(List<XpsDocument> ListToMerge)
    {
        var memoryStream = new MemoryStream();
        Package container = Package.Open(memoryStream, FileMode.Create);
        string pack = "pack://temp.xps"; 
        PackageStore.RemovePackage(new Uri(pack));
        PackageStore.AddPackage(new Uri(pack), container);

        XpsDocument xpsDoc = new XpsDocument(container, CompressionOption.SuperFast, "pack://temp.xps");
        FixedDocumentSequence seqNew = new FixedDocumentSequence();
        foreach (var sourceDocument in ListToMerge)
        {
            FixedDocumentSequence seqOld = sourceDocument.GetFixedDocumentSequence();
            foreach (DocumentReference r in seqOld.References)
            {
                DocumentReference newRef = new DocumentReference();
                ((IUriContext)newRef).BaseUri = ((IUriContext)r).BaseUri;
                newRef.Source = r.Source;
                seqNew.References.Add(newRef);
            }
        }
        XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
        xpsWriter.Write(seqNew);
        //xpsDoc.Close();
        //container.Close();
        return xpsDoc;
    }

the result goes to DocumentViewer and display it to user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:29:28+00:00Added an answer on June 7, 2026 at 4:29 pm

    I created following function and it works for me.

        public void MergeXpsDocument(string newFile, List<XpsDocument> sourceDocuments)
        {
            if (File.Exists(newFile))
            {
                File.Delete(newFile);
            }
    
            XpsDocument xpsDocument = new XpsDocument(newFile, System.IO.FileAccess.ReadWrite);
            XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
            FixedDocumentSequence fixedDocumentSequence = new FixedDocumentSequence();
    
            foreach(XpsDocument doc in sourceDocuments)
            {
                FixedDocumentSequence sourceSequence = doc.GetFixedDocumentSequence();
                foreach (DocumentReference dr in sourceSequence.References)
                {
                    DocumentReference newDocumentReference = new DocumentReference();
                    newDocumentReference.Source = dr.Source;
                    (newDocumentReference as IUriContext).BaseUri = (dr as IUriContext).BaseUri;
                    FixedDocument fd = newDocumentReference.GetDocument(true);
                    newDocumentReference.SetDocument(fd);
                    fixedDocumentSequence.References.Add(newDocumentReference);
                }
            }
            xpsDocumentWriter.Write(fixedDocumentSequence);
            xpsDocument.Close();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the problem. Write a function for merging multiple (sorted) linked lists into one
I have this problem where I'm merging changes up into my integration branch but
I have problem merging two XML files. I loaded both files into two objects,
I have problem while loading data into html select when users press or click
I am thinking about different solutions for one problem. Assume we have K sorted
I have a productdatabase that contains products, parts and labels for each part based
I have a problem with merging two projects compiled separately. I created some classes
reference from: Merging Variable PHP I have problem with $_POST getting blank null after
Hi I have really problem with merging two lists in such code like mergesort
I have a problem merging from trunk to my branch. I created the branch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.