几年前,我找到了一些示例代码,可以很好地打印listview的内容,在每个页面中重复一个文档头、页脚和表头。
基本上,有一个类实现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是从清单视图创建的网格,具有相同的列
在过去的一年里,使用不同的操作系统和不同的.net框架,它正确地工作,现在这个表被切割在右边,大约占总宽度的60%。
页面方向被设置为景观和计算是用景观值,但在打印过程中,它似乎被认为是‘肖像’,并削减在限制。
发布于 2021-07-26 10:33:09
打印代码来自Codeproject,自定义数据网格文档分页器上的一个旧项目。
如前所述,我相信它在过去很好的工作,改变页面的方向为景观,现在它削减了表的页面肖像宽度。
DocumentPage有两个构造函数:
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,它正确地工作。最初的源代码使用的是第一个,可视化是测量和排列成景观维度,而DocumentPage使用的是肖像维度。这与10年前的行为不同,不知道这种变化是什么时候发生的。
https://stackoverflow.com/questions/68224795
复制相似问题