我有:
DocumentPaginator dp = ((IDocumentPaginatorSource)document).DocumentPaginator;
和
FlowDocument document = new FlowDocument();
// create a flow document...
如何使用DocumentPaginator将FlowDocument转换为FixedDocument?我似乎无法找到如何做到这一点。我查看的所有网站都使用XpsWriter:
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
DocumentPaginator dp = ((IDocumentPaginatorSource)document).DocumentPaginator;
writer.Write(dp);
我可以编写XPS然后返回FixedDocument但是必须有更好的方法吗?
答案 0 :(得分:6)
不,似乎没有更好的方法。但是您不需要将其保存到磁盘:
var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
var package = Package.Open(new MemoryStream(), FileMode.Create, FileAccess.ReadWrite);
var packUri = new Uri("pack://temp.xps");
PackageStore.RemovePackage(packUri);
PackageStore.AddPackage(packUri, package);
var xps = new XpsDocument(package, CompressionOption.NotCompressed, packUri.ToString());
XpsDocument.CreateXpsDocumentWriter(xps).Write(paginator);
FixedDocument doc = xps.GetFixedDocumentSequence().References[0].GetDocument(true);