如何使用FlowDocument的IDocumentPaginatorSource DocumentPaginator将FlowDocument转换为FixedDocument?



我有:

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,但肯定有更好的方法吗?

不,似乎没有更好的方法了。但您不需要将其保存到磁盘:

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);

相关内容

  • 没有找到相关文章

最新更新