如何在 C# 中打印文档为灰度模式

This article was translated from English: Does it need improvement?
Translated
View the article in English

Printing in grayscale converts color documents to black-and-white output at the printer driver level. This preserves colored ink or toner cartridges during high-volume batch runs, keeps internal drafts readable without wasting expensive consumables, and meets formatting requirements where monochrome output is preferred.

IronPrint makes this a single boolean: set PrintSettings.Grayscale to true, and the printer produces black-and-white output regardless of the document's original colors. We cover installation, basic usage, async workflows, and combined settings below.

Quickstart: Print in Grayscale

  1. Install IronPrint via NuGet: Install-Package IronPrint
  2. Add using IronPrint; to the file
  3. Create a PrintSettings object
  4. Set Grayscale to true
  5. Pass settings to Printer.Print() with the file path
  1. 使用 NuGet 包管理器安装 https://www.nuget.org/packages/IronPrint

    PM > Install-Package IronPrint
  2. 复制并运行这段代码。

    using IronPrint;
    
    // Print in grayscale — one property, one line
    PrintSettings settings = new PrintSettings();
    settings.Grayscale = true;
    Printer.Print("report.pdf", settings);
  3. 部署到您的生产环境中进行测试

    通过免费试用立即在您的项目中开始使用IronPrint

    arrow pointer

如何为静默打印文档启用灰度模式?

To print in grayscale without any user interaction, we enable the Grayscale property and pass the settings to Printer.Print():

:path=/static-assets/print/content-code-examples/how-to/grayscale-printing/grayscale-printing-silent-grayscale.cs
using IronPrint;

// Silently print a color PDF as black-and-white
PrintSettings settings = new PrintSettings
{
    Grayscale = true
};

Printer.Print("color-brochure.pdf", settings);
Imports IronPrint

' Silently print a color PDF as black-and-white
Dim settings As New PrintSettings With {
    .Grayscale = True
}

Printer.Print("color-brochure.pdf", settings)
$vbLabelText   $csharpLabel

When Grayscale is true, the printer driver strips color information before laying ink or toner on the page. The original file remains unchanged — only the printed output is monochrome. This is the same behavior as manually selecting "Black & White" or "Grayscale" in the Windows print dialog, except we control it programmatically without any user interaction.

Grayscale defaults to false when not explicitly set, meaning documents print in full color by default.

何时应使用灰度打印文档?

Grayscale printing is the right choice in several common scenarios:

Cost reduction — Color toner cartridges cost significantly more than black cartridges. Switching internal-facing documents (drafts, timesheets, internal memos) to grayscale can reduce per-page printing costs substantially over a quarter.

Readability — Documents with light-colored text or pastel backgrounds can be difficult to read on paper. Grayscale conversion often improves contrast and legibility for text-heavy content.

Compliance and archival — Some regulated industries require monochrome copies for filing. Grayscale output meets this requirement without modifying the source document.

For documents where color accuracy matters — marketing collateral, branded materials, charts with color-coded data — leave Grayscale at its default false value.

如何将灰度与其他打印设置结合使用?

Grayscale is one property on PrintSettings. We can combine it with paper margins, paper size, orientation, DPI, number of copies, and printer selection in a single configuration object:

:path=/static-assets/print/content-code-examples/how-to/grayscale-printing/grayscale-printing-combined-settings.cs
using IronPrint;

// Full configuration: grayscale draft printing for internal distribution
PrintSettings settings = new PrintSettings
{
    Grayscale = true,
    NumberOfCopies = 10,
    PaperSize = PaperSize.A4,
    PaperOrientation = PaperOrientation.Portrait,
    Dpi = 150,
    PaperMargins = new Margins(15),
    PrinterName = "Office Mono Laser"
};

Printer.Print("team-memo.pdf", settings);
Imports IronPrint

' Full configuration: grayscale draft printing for internal distribution
Dim settings As New PrintSettings With {
    .Grayscale = True,
    .NumberOfCopies = 10,
    .PaperSize = PaperSize.A4,
    .PaperOrientation = PaperOrientation.Portrait,
    .Dpi = 150,
    .PaperMargins = New Margins(15),
    .PrinterName = "Office Mono Laser"
}

Printer.Print("team-memo.pdf", settings)
$vbLabelText   $csharpLabel

Pairing Grayscale = true with a lower DPI like 150 creates a fast, economical draft-printing configuration ideal for high-volume internal documents. For non-blocking workflows, pass the same PrintSettings to Printer.PrintAsync() instead.

哪些文件格式支持灰度打印?

IronPrint supports grayscale output for every file format the library handles: PDF, PNG, TIFF, GIF, JPEG, and BMP. The Grayscale property applies identically regardless of the source format — we pass the same PrintSettings object to Printer.Print() whether we are printing a PDF report or a JPEG photograph.

For PDF-specific workflows that require converting the file itself to grayscale before printing, IronPDF's grayscale rendering provides that capability. IronPrint's Grayscale property, by contrast, keeps the source file in color and only affects the printed output.

我的下一个步骤是什么?

We covered how to enable grayscale printing with PrintSettings.Grayscale = true, demonstrated silent and async grayscale workflows, discussed when monochrome output makes sense, combined grayscale with other settings for draft-quality batch printing, and confirmed format support across all IronPrint-compatible file types.

欲了解更多信息,请探索以下资源:

Get a free trial license to test every feature in a live environment, or view licensing options when you're ready to deploy.

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 38,930 | 版本: 2026.4 刚刚发布
Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package IronPrint
运行示例 观看您的文档打到打印机上。