我想从我的 WPF 应用程序生成(然后打印或保存)大型 XPS 文档(>400 页)。我们有大量的内存数据需要写入 XPS。
如何在没有 OutOfMemoryException
的情况下做到这一点?有没有办法可以分 block 编写文档?这通常是怎么做的?我不应该首先将 XPS 用于大文件吗?
OutOfMemoryException
的根本原因似乎是巨大的FlowDocument
的创建。我正在创建完整的 FlowDocument
,然后将其发送给 XPS 文档编写器。这是错误的方法吗?
最佳答案
你是怎么做到的?你没有显示任何代码。
我使用 XpsDocumentWriter 以 block 的形式写入,如下所示:
FlowDocument flowDocument = . .. ..;
// write the XPS document
using (XpsDocument doc = new XpsDocument(fileName, FileAccess.ReadWrite))
{
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
// Change the PageSize and PagePadding for the document
// to match the CanvasSize for the printer device.
paginator.PageSize = new Size(816, 1056);
copy.PagePadding = new Thickness(72);
copy.ColumnWidth = double.PositiveInfinity;
writer.Write(paginator);
}
这不适合你吗?
关于wpf - 如何在 WPF 中生成和打印大型 XPS 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2342623/