首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DocumentPaginator:只打印了一半网格

DocumentPaginator:只打印了一半网格
EN

Stack Overflow用户
提问于 2021-07-02 11:57:07
回答 1查看 91关注 0票数 0

几年前,我找到了一些示例代码,可以很好地打印listview的内容,在每个页面中重复一个文档头、页脚和表头。

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

下面是启动打印的代码:

代码语言:javascript
复制
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)中的代码,用于调整网格维数:

代码语言:javascript
复制
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%。

页面方向被设置为景观和计算是用景观值,但在打印过程中,它似乎被认为是‘肖像’,并削减在限制。

EN

回答 1

Stack Overflow用户

发布于 2021-07-26 10:33:09

打印代码来自Codeproject自定义数据网格文档分页器上的一个旧项目。

如前所述,我相信它在过去很好的工作,改变页面的方向为景观,现在它削减了表的页面肖像宽度。

DocumentPage有两个构造函数:

代码语言:javascript
复制
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年前的行为不同,不知道这种变化是什么时候发生的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68224795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档