WPF-打印视觉效果时的分页 [英] WPF - pagination when printing a visual

查看:109
本文介绍了WPF-打印视觉效果时的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有框架的WPF窗口.我有一些代码可以使用printdialog和printvisual打印出框架的内容.但这仅会打印屏幕上显示的内容,即使框架滚动和其他部分可用.

I have a WPF window with a frame. I have some code to print out the content of the frame using the printdialog and printvisual. But this will only print what appears on the screen even though the frame scrolls and other parts are available.

是否可以添加分页并确保可以打印框架的全部内容.

Is there a way to add pagination and make sure that the entire content of my frame will print.

或者还有其他方法可以获取我的框架内容并将其打印出来?即不使用printvisual?

Or is there another way to take my frame content and print it? i.e. to not use printvisual?

推荐答案

是.我已经做到了这不是很困难.

Yes. I've done this. It is not very difficult.

  1. 将框架包装在通常禁用水平和垂直滚动的ScrollViewer中

  1. Wrap your Frame inside a ScrollViewer which normally has its horizontal and vertical scrolling disabled

准备打印时,启用垂直滚动.这将导致Frame被告知具有无限的垂直空间,因此它将呈现所有内容.然后调用UpdateLayout()获取要更新的布局.

When you're ready to print, enable vertical scrolling. This will cause the Frame to be told it has infinite vertical space, so it will render all of the content. Then call UpdateLayout() to get the layout to update.

实施IDocumentPaginator,以便为每个页面返回相同的Frame,但每次都要调整剪辑和RenderTransform,以显示实际Frame的不同部分.

Implement IDocumentPaginator to return the same Frame for each page but adjust the clip and RenderTransform each time to show a different portion of the actual Frame.

使用您的自定义IDocumentPaginator打印

Print using your custom IDocumentPaginator

以上描述假定您要将框架的宽度固定为页面宽度并垂直分页.这将适用于网页,但不适用于电子表格.对于类似电子表格的内容,您可以将ScrollViewer设置为允许在两个方向上滚动,从而为框架提供无限的空间.在这种情况下,IDocumentPaginator相同,只是选择了RenderTransforms和Clipping可以在水平和垂直方向上进行迭代.

The above description assumes that you want to fix the width of the frame to the page width and paginate it vertically. This would be appropriate for a web page but not for a spreadsheet. For spreadsheet-like content you would set the ScrollViewer to allow scrolling in both directions, giving the frame infinite space each way. In this case the IDocumentPaginator is the same except the RenderTransforms and clipping are chosen to iterate both horizontally and vertically.

该技术实际上适用于任何WPF内容,而不仅仅是帧.

This technique actually works for any WPF content, not just a Frame.

另请参见
WPF视觉文件的分页打印

这篇关于WPF-打印视觉效果时的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆