2012-03-12 104 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