【问题标题】:Print With No Margin无边距打印
【发布时间】:2012-03-29 07:10:11
【问题描述】:

我正在尝试打印一个 4" 高 x 3" 宽的 WPF 控件。

我在控件上使用了ScaleTransformCanvas)来相应地缩放它;但是,当我打印到打印机时,图像的一部分被切断(顶部和左侧边缘)。

根据this thread

这个问题的原因是打印机在纸的边缘提供了一个未打印的边距,但是PrintDialog.PrintVisual方法打算打印到纸的边缘。因此,位于纸张边缘周围未打印边距中的区域被剪裁。

线程没有提及如何检索边距或如何强制打印机忽略这些边距。如何获取这些值以便使用 WPF 进行打印而不进行裁剪?

【问题讨论】:

    标签: wpf printing


    【解决方案1】:

    您需要将来自PrintDocumentImageableArea 的信息与UIElement 上的MeasureArrange 成员结合起来:

    // 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
    }
    

    【讨论】:

    • 谢谢,我正在尝试。
    • 非常感谢您的帮助。有效。我必须将边距(乘以 2 以获得左侧、右侧、顶部和底部)添加到我尝试打印的项目的大小。我在 Measure 和 Arrange 方法中使用了这个尺寸(从顶部的左边距开始 Arrange 方法)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    相关资源
    最近更新 更多