wpf - 如何在 WPF 中生成和打印大型 XPS 文档?

标签 wpf memory printing xps

我想从我的 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/

相关文章:

C# WPF DataGrid 不显示来自 SQLite 3 数据库的小数

c# - 如何将 DatePicker 中的 SelectedDateChanged 事件绑定(bind)到 VM 中的命令

c - 为什么数组的第一个值被替换?

macos - 在 Mac 上使用 Python 打印到 USB 打印机

asp.net - 最大限度地减少实现可打印报告的痛苦

WPF:在没有打印对话框的情况下打印 FlowDocument

c - 故意浪费所有的主内存来学习碎片

perl - 是否有一个 Perl 统计包不能让我一次加载整个数据集?

java - 如何简化标签打印对齐配置?

c# - 如果安装了 IE9,WPF 4.0 WebBrowser Control 是否支持 HTML5?