2012-03-12 139 views
4

我正在尝试打印4英寸宽的“3”宽的WPF控件。无边距打印

我已经在控件上使用了一个ScaleTransform(一个Canvas)来相应地缩放它;然而,当我打印到打印机的部分图像被切断(顶部和左边缘)。

根据this thread

这个问题的原因是打印机提供了围绕纸张的边缘未印刷的利润率,但PrintDialog.PrintVisual方法所要打印到纸张的边缘。因此位于纸张边缘未印刷边缘的区域会被裁剪。

线程未能提及如何检索边距或如何强制打印机忽略这些边距。如何获得这些值,以便我可以使用WPF进行打印而不进行裁剪?

回答

5

你需要的信息从PrintDocumentImageableAreaMeasureArrange成员的UIElement结合:

// I could not find another way to change the margins other than the dialog 
var result = printDialog.ShowDialog(); 
if (result.HasValue && result.Value) 
{ 
    var queue = printDialog.PrintQueue; 

    // Contains extents and offsets 
    var area = queue.GetPrintCapabilities(printDialog.PrintTicket) 
        .PageImageableArea; 

    // scale = area.ExtentWidth and area.ExtentHeight and your UIElement's bounds 
    // margin = area.OriginWidth and area.OriginHeight 
    // 1. Use the scale in your ScaleTransform 
    // 2. Use the margin and extent information to Measure and Arrange 
    // 3. Print the visual 
} 
+0

谢谢你,现在我想它。 – Frinavale 2012-03-13 13:06:07

+0

非常感谢您的帮助。有效。我必须添加边距(乘以2来获得左侧,右侧,顶部和底部)到我试图打印的项目的大小。我在Measure和Arrange方法中使用了这个尺寸(在顶部开始编配方法,左边距)。 – Frinavale 2012-03-13 14:21:55