2
여러 개의 XPS 문서를 하나로 병합 할 때 문제가 있습니다. 병합 할 때 결과 xps에는 복제 된 마지막 XPS 문서가 들어 있습니다.xps 문서를 병합하면 마지막 하나가 복제됩니다.
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;
}
결과가 DocumentViewer로 이동하고 사용자에게 표시 : 여기에 병합 내 기능 (Modified version of this question)입니다.
다른 샘플은 내가 누구의 FixedDocumentSequence 소스 문서의 모든 페이지를 포함하는 단일 FixedDocument를 포함하는 새로운 XPS 파일을 생성, 여러 소스 XPS 문서에서 페이지를 추출 봤어요. 이것은 FixedDocumentSequence에 새로운 FixedDocument 객체를 추가 한 유일한 샘플입니다. –
매력처럼 작동했습니다. 감사! –