本文介绍了如何使用的FlowDocument的IDocumentPaginatorSource DocumentPaginator的FlowDocument转换为固定文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
DocumentPaginator dp = ((IDocumentPaginatorSource)document).DocumentPaginator;
和
FlowDocument document = new FlowDocument();
// create a flow document...
如何做一个转换的FlowDocument使用DocumentPaginator一个固定文档?我似乎无法找出如何做到这一点。所有的网站我看了看使用XpsWriter如:
How do a convert the FlowDocument to a FixedDocument using the DocumentPaginator? I can't seem to find out how to do this. All sites I looked at use XpsWriter as in:
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
DocumentPaginator dp = ((IDocumentPaginatorSource)document).DocumentPaginator;
writer.Write(dp);
我可以写的XPS,然后取回固定文档,但必须有一个更好的办法?
I could write the XPS and then get back the FixedDocument but there must be a better way?
推荐答案
没有,似乎没有成为一个更好的办法。但你并不需要把它保存到磁盘:
No, there doesn't seem to be a better way. But you don't need to save it to disk:
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);
这篇关于如何使用的FlowDocument的IDocumentPaginatorSource DocumentPaginator的FlowDocument转换为固定文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!