You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI macOS端如何隐藏默认打印UI中的缩放选项?

在.NET MAUI macOS应用中隐藏打印UI的缩放选项

要实现类似Mac照片应用的无缩放选项打印UI,你需要放弃直接设置PrintingItem的方式,改用UIImagePrintFormatter来控制打印布局,具体修改如下:

  1. 移除原代码中的printer.PrintingItem = uiimage;
  2. 创建UIImagePrintFormatter实例,绑定你的图片并配置自动缩放
  3. 将这个formatter赋值给打印控制器的PrintFormatter属性

修改后的完整代码:

img?.Seek(0, SeekOrigin.Begin);
var data = NSData.FromStream(img);
var uiimage = UIImage.LoadFromData(data);

var printer = UIPrintInteractionController.SharedPrintController;

if (printer == null)
{
    // Log Error
}
else
{
    var printInfo = UIPrintInfo.PrintInfo;
    printInfo.OutputType = UIPrintInfoOutputType.Photo;
    printer.PrintInfo = printInfo;

    // 替换原PrintingItem的设置,改用PrintFormatter
    var printFormatter = new UIImagePrintFormatter(uiimage);
    printFormatter.ScalesToFit = true; // 自动适配纸张尺寸,无需手动缩放
    printer.PrintFormatter = printFormatter;

    var handler = new UIPrintInteractionCompletionHandler(async (printInteractionController, completed, error) =>
    {
        if (!completed && error != null)
        {
            // Log error
        }
    });
    printer.Present(true, handler);
}

这样设置后,打印UI会自动将图片适配到纸张大小,同时隐藏手动缩放的选项,和你期望的Mac照片应用效果一致。

内容的提问来源于stack exchange,提问作者kiran mohanty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 04:59:58