WPF DocumentPaginator 和 DocumentPage 意外裁剪
我正在尝试在多个页面上打印 WPF 画布。
我非常满意将其缩放以适合页面宽度,然后剪切并翻译每个页面的画布;所有这些都是非常简单的数学。
我不明白的是如何获得可打印区域的尺寸,以及如何告诉打印机打印到哪里。无论我尝试什么,我使用的值似乎都是纸张的尺寸,因此,当打印机无法直接打印到纸张边缘时,我会发生裁剪。
var capabilities = printDialog.GetPrintCapabilities(dialog.PrintTicket);
功能具有以下属性:
capabilities.PageImageableArea.ExtentWidth
// "Gets the width of the imageable area"
什么是“可成像”区域?这是纸张上我可以放置内容的区域吗?我猜是因为:
capabilities.PageImageableArea.OriginWidth
// Gets the distance from the left edge of the page to the imageable area.
但是底部和右边距呢?我在哪里可以找到这些信息?
DocumentPaginator
的 PageSize
属性应该设置为什么?我应该从 capability.PageImageableArea
中设置它吗?或者 dialog.Print()
函数是否设置了这个,而我只需要在 GetPage()
中读取它?
最后,当我返回 DocumentPage
时,我应该将什么传递给三个几何参数 pageSize
、bleedBox
和 contentBox
?
谢谢 :)
I'm trying to print a WPF canvas over multiple pages.
I'm perfectly happy with scaling it to fit on the page width, then clipping and translating the canvas for each page; all pretty simple maths.
What I don't understand is how I get the dimensions of the printable area, and how to tell the printer where to print to. Whatever I try it appears the values I'm using are the size of the paper, and i therefore get cropping occurring as the printer cant print right to the edge of the paper.
var capabilities = printDialog.GetPrintCapabilities(dialog.PrintTicket);
capabilities has the following properties:
capabilities.PageImageableArea.ExtentWidth
// "Gets the width of the imageable area"
What is the "imageable" area? is that the area on the paper in which I can put content? I guess so because:
capabilities.PageImageableArea.OriginWidth
// Gets the distance from the left edge of the page to the imageable area.
However what about the bottom and right margins? Where do I find this information?
What should the PageSize
property of the DocumentPaginator
be set to? Should I set this from capabilities.PageImageableArea
? Or does the dialog.Print()
function set this, and i just need to read from it in GetPage()
?
Finally, when I return a DocumentPage
, what do I pass to the three geometry arguments pageSize
, bleedBox
and contentBox
?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,打印似乎总是从纸张的
(0, 0)
(左上角)开始。获取纸张的大小:
以及顶部和左侧边距:
我假设底部和右侧边距与顶部和左侧相同,尽管这可能不安全。
您必须像平常一样缩放和裁剪画布,然后应用边距大小的 TranslateTransform 将内容移动到可打印区域。
Ok it seems that printing always occurs from
(0, 0)
(top left) of the paper.Get the size of the paper with:
and the top and left margins with:
I assumed that the bottom and right margins were the same as the top and left, although this may not be safe.
You have to scale and clip the canvas as you normally would, then apply a
TranslateTransform
the size of your margins to move the content in to the printable area.您是否考虑过使用 FlowDocument 而不仅仅是打印 Canvas?有一个创建和打印
希望这会消除对大量数学的需要。
Have you looked at using a FlowDocument instead of just printing the Canvas? there is a good example of creating and printing Here.
Hopefully that would negate the need for a lot of the Math.