我有:
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);