【发布时间】: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% 的总宽度。
页面方向设置为横向,并使用横向值进行计算,但在打印过程中,文档似乎被视为“纵向”并在限制处剪切。
【问题讨论】: