附加XPS文档到现有 [英] Appending an XPS document to an existing one
问题描述
大家好,这里是我在哪里卡住了。
我有一个需要从微小的XPS文件,一个巨大的一堆创建一个单一的XPS文件。问题是,我一直运行内存,当我尝试这样做。
我目前的代码(从MSDN拍摄)以下的,但本质上它是所有这:
- 它读取每一个微小的XPS文件
- 从它提取页
- 将这些页面到文档序列。
- 当所有的文档都完成后,将其写入该序列到合并XPS文档。
IMO,我的文档序列越来越太大。所以,我想,也许我可以用一块做这一块 - 即追加微小的XPS文档的合并XPS文档逐个
现在,我不知道该怎么做。 ?任何指针
代码:
//创建新的XPS包
套餐combinedXPS = Package.Open(文件名,FileMode.Create);
XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(新XpsDocument(combinedXPS));
文档序列combinedSequence =新文档序列();
//通过给定的
的foreach(在文件名中的字符串文件)
{
//装载XPS包
XpsDocument singleXPS =新XpsDocument每个文件去(文件,FileAccess.Read);
文档序列singleSequence = singleXPS.GetFixedDocumentSequence();
//通过在文件
的foreach每个文档(DocumentReference的docRef在singleSequence.References)
{
固定文档oldDoc = docRef.GetDocument(假)进入;
固定文档newDoc =新的固定文档();
DocumentReference的newDocReference =新DocumentReference的();
newDocReference.SetDocument(newDoc);
//通过每个页面
去的foreach(在oldDoc.Pages PageContent页)
{
PageContent NEWPAGE =新PageContent();
newPage.Source = page.Source;
(NewPage公司作为IUriContext).BaseUri =((IUriContext)页).BaseUri;
newPage.GetPageRoot(真);
newDoc.Pages.Add(新页);
}
//添加文件打包
combinedSequence.References.Add(newDocReference);
}
singleXPS.Close();
}
xpsWriter.Write(combinedSequence);
combinedXPS.Close();
XPS文档只是的压缩了 XAML文件,我敢打赌,你可以只直接写出所有源文件的XML没有保留它全部在内存中,然后压缩它。甚至还有.NET API来帮助你处理这些类型的文件直接的。
Guys, here's where I am stuck.
I have a need to create a single XPS file from a huge bunch of tiny XPS files. The problem is that I keep running out of memory when I try to do this.
I present below the code (taken from MSDN), but essentially all it does is this:
- It reads each tiny XPS file
- Extracts the pages from it.
- Adds these pages to a FixedDocumentSequence.
- When all docs are done, it writes this sequence out to the combined XPS doc.
IMO, my FixedDocumentSequence is getting too big. So, I am thinking, that maybe I can do this piece by piece - i.e. append the tiny XPS docs to the combined XPS docs one by one.
Now, I don't know how to do that. 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();
XPS documents are just zipped up XAML files, I bet you could just directly write out an XML from all of the source files without keeping it all in memory, then zip it up. There's even .NET APIs that help you deal with these kinds of files directly.
这篇关于附加XPS文档到现有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!