gpt4 book ai didi

wpf - 无边距打印

转载 作者:行者123 更新时间:2023-12-02 05:00:30 27 4
gpt4 key购买 nike

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

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

根据this thread :

The reason of this problem is that the printer provides an unprinted margin around the edge of the paper, but the PrintDialog.PrintVisual method intends to print to the edge of the paper. So the area that lies in the unprinted margin around the edge of the paper is clipped.

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

最佳答案

您需要将 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
}

关于wpf - 无边距打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9674628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com