伙计们,这就是我被困住的地方。
我需要从一大堆微小的XPS文件中创建一个XPS文件。问题是当我尝试这样做时,我的内存不足。
我在代码下面(取自MSDN),但基本上它只是这样:
现在,我不知道该怎么做。有什么指针吗?
代码:
//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();
答案 0 :(得分:2)
XPS文档只是zipped up个XAML文件,我打赌你可以直接从所有源文件中写出一个XML,而不是将它全部保存在内存中,然后将其压缩。甚至还有.NET API可以帮助您直接处理这些类型的文件。