你怎么做呢?您没有显示任何代码.
我使用XpsDocumentWriter来编写块,如下所示:
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);
}
Run Code Online (Sandbox Code Playgroud)
这不适合你吗?
我可以确认 XPS 不会在长文档上引发内存不足。无论是在理论上(因为 XPS 上的操作是基于页面的,它不会尝试将整个文档加载到内存中),还是在实践中(我使用基于 XPS 的报告,并且看到失控的错误消息总计达数千条)页)。
难道问题出在一个特别大的页面上?例如,一张巨大的图像?大页面具有高 DPI 分辨率?如果文档中的单个对象太大而无法一次分配,则会导致内存不足异常。