Guys, here I am stuck.
I need to create one XPS file from a huge group of tiny XPS files. The problem is that I run out of memory when I try to do this.
Below is the code (taken from MSDN), but essentially all it does is:
- It reads every tiny XPS file.
- Retrieves pages from it.
- Adds these pages to a FixedDocumentSequence.
- When all documents are completed, he writes this sequence to the combined XPS document.
IMO, my FixedDocumentSequence is getting too big. So, I think that maybe I can do it in parts - for example, add tiny XPS documents to the combined XPS documents one at a time.
Now I do not know how to do this. Any pointers?
code:
//Create new xps package Package combinedXPS = Package.Open(filename, FileMode.Create); XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(new XpsDocument(combinedXPS)); FixedDocumentSequence combinedSequence = new FixedDocumentSequence(); //Go through each file given foreach (string file in filenames) { //Load Xps Package XpsDocument singleXPS = new XpsDocument(file, FileAccess.Read); FixedDocumentSequence singleSequence = singleXPS.GetFixedDocumentSequence(); //Go through each document in the file foreach (DocumentReference docRef in singleSequence.References) { FixedDocument oldDoc = docRef.GetDocument(false); FixedDocument newDoc = new FixedDocument(); DocumentReference newDocReference = new DocumentReference(); newDocReference.SetDocument(newDoc); //Go through each page foreach (PageContent page in oldDoc.Pages) { PageContent newPage = new PageContent(); newPage.Source = page.Source; (newPage as IUriContext).BaseUri = ((IUriContext)page).BaseUri; newPage.GetPageRoot(true); newDoc.Pages.Add(newPage); } //Add the document to package combinedSequence.References.Add(newDocReference); } singleXPS.Close(); } xpsWriter.Write(combinedSequence); combinedXPS.Close();
source share