【问题标题】:DocumentPaginator: only half grid is printedDocumentPaginator:只打印半个网格
【发布时间】:2021-07-02 11:57:07
【问题描述】:

几年前,我发现了一些示例代码可以漂亮地打印列表视图的内容,在每一页中重复文档页眉、页脚和表格页眉。

基本上有一个类实现DocumentPaginator并计算适合页面的行数

这是启动打印的代码:

PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;
printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
Size pageSize = new Size(printDialog.PrintableAreaWidth, 
printDialog.PrintableAreaHeight);
DocumentPaginator paginator = new SimpleListDocumentPaginator(param as ListView, 
documentTitle, pageSize, new Thickness(30, 20, 60, 20));
printDialog.PrintDocument(paginator, "Somename");

这是 GetPage(int pageNumber) 中调整网格尺寸的代码:

double width = this.PageSize.Width - (this.PageMargin.Left + this.PageMargin.Right);
double height = this.PageSize.Height - (this.PageMargin.Top + this.PageMargin.Bottom);
pageGrid.Measure(new Size(width, height));
pageGrid.Arrange(new Rect(this.PageMargin.Left, this.PageMargin.Top, width, height));
return new DocumentPage(pageGrid);

pageGrid 是从 Listview 创建的网格,具有相同的列

在过去的一年中,使用不同的操作系统和不同的 .net 框架,它可以正常工作,现在表格在右侧被削减了大约 60% 的总宽度。

页面方向设置为横向,并使用横向值进行计算,但在打印过程中,文档似乎被视为“纵向”并在限制处剪切。

【问题讨论】:

    标签: wpf printing


    【解决方案1】:

    打印代码来自 Codeproject 上的一个旧项目,Custom Data Grid Document Paginator

    如上所述,我确信它在过去将页面方向更改为横向时效果很好,现在它以页面纵向宽度切割表格。

    DocumentPage 有 2 个构造函数:

    public DocumentPage (System.Windows.Media.Visual visual);
    public DocumentPage (System.Windows.Media.Visual visual, System.Windows.Size pageSize, System.Windows.Rect bleedBox, System.Windows.Rect contentBox);
    

    使用第二个并传递正确的 pageSize 它可以正常工作。原始源代码使用第一个,visual测量和排列到 Landscape 维度,但 DocumentPage 使用 Portrait 维度。这和10年前不一样了,不知道什么时候发生的变化。

    【讨论】:

      猜你喜欢
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多