IRONSOFTWAREHOME

C# Print Document Tutorial with IronPrint

Curtis Chau
Curtis Chau
Updated: 2026年4月22日

IronPrint 是一款強大的列印程式庫,旨在協助 .NET C# 開發人員將列印功能整合至其應用程式中。 IronPrint 具備廣泛的相容性,涵蓋 Windows、macOS、iOS 及 Android 平台,能在各種作業系統上提供一致且可靠的運作表現。 無論您是為桌面環境、Apple 的 macOS 生態系統,還是 iOS 和 Android 等行動平台開發應用程式,IronPrint 都能簡化列印功能的實作,為您在 .NET C# 環境中的所有列印需求提供多功能且易於使用的解決方案。

快速入門:使用 IronPrint 靜默列印文件

只需一行程式碼即可開始列印——無需對話方塊,毫無繁瑣步驟。 使用 IronPrint.Printer.Print(...) 可透過預設或自訂設定,將 PDF 或圖片直接傳送至印表機。

  1. 1Install IronPrint with NuGet Package Manager

    PM > Install-Package IronPrint

  2. 2複製並運行這段程式碼片段。

    IronPrint.Printer.Print("path/to/your/document.pdf");
    C#
  3. 3部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronPrint,透過免費試用
    arrow pointer

目錄

列印文件

靜默列印

無需顯示列印對話方塊,即可無縫列印文件。 隨後即可直接在程式碼中進行PRINT設定。

// Programmatically print a document without showing the print dialog.
// Define your print job and settings here as needed.

using System;
using IronPrint;

public class SilentPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a silent print job
        var printJob = new PrintJob(document);

        // Apply specific settings as necessary
        // For example: set printer name, copies, etc.
        
        // Execute the print job
        printJob.PrintSilently();
    }
}

透過對話方塊列印

在顯示列印設定對話方塊時,啟動列印程式。 這讓使用者能夠以互動方式自訂PRINT選項。

// Start a print job with user interaction through the print dialog.

using System;
using IronPrint;

public class DialogPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a print job with dialog
        var printJob = new PrintJob(document);

        // Execute the print job with display of print options dialog
        printJob.PrintWithDialog();
    }
}

套用列印設定

透過程式化方式調整PRINT設定,以滿足特定需求。 本節提供透過程式碼微調列印設定的功能。

// Example code to apply custom print settings programmatically.

using System;
using IronPrint;

public class PrintSettingsExample
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Create a print job
        var printJob = new PrintJob(document);

        // Set custom print settings like duplex, color mode, etc.
        var settings = new PrintSettings
        {
            ColorMode = ColorMode.Color,
            DuplexMode = DuplexMode.OneSided,
            Copies = 2
        };

        // Apply settings to print job
        printJob.ApplySettings(settings);

        // Print the document
        printJob.PrintSilently();
    }
}

取得印表機資訊

取得印表機名稱

取得所有可用印表機的清單。 檢索系統上已安裝的印表機名稱,供參考之用,或用於應用程式中的動態印表機選取。

// Retrieve and display a list of printer names available on the system.

using System;
using IronPrint;

public class PrinterInfo
{
    public static void Main()
    {
        // Get an enumerable list of printer names
        var printerNames = PrinterSettings.GetAvailablePrinters();

        // Print each printer name to the console
        Console.WriteLine("Available Printers:");
        foreach (var name in printerNames)
        {
            Console.WriteLine(name);
        }
    }
}

常見問題

如何在.NET C#中靜默列印文件?

您可以使用PrintJob實例的PrintSilently()方法來執行無需使用者互動的列印作業。這允許文件以程式方式列印,而無需顯示列印對話框。

在.NET C#中使用列印對話框列印文件的流程是什麼?

您可以通過使用PrintJob實例上的PrintWithDialog()方法來啟動具有使用者互動的列印作業。這將顯示列印設置對話框,允許使用者在列印前自訂選項。

是否可以在.NET C#中程式化地應用自訂列印設置?

是的,您可以通過建立PrintSettings物件並配置諸如顏色模式、雙面模式和副本數量等屬性來程式化地應用自訂列印設置。然後可以將這些設置應用到PrintJob實例。

如何在.NET C#應用程式中檢索可用的列印機名稱?

您可以使用PrinterSettings.GetAvailablePrinters()方法檢索可用的列印機名稱。這提供了一個可枚舉的系統中安裝的列印機名稱列表,用於選擇或資訊用途。

我可以使用.NET C# 庫列印不同的文件格式嗎?

是的,該庫支援列印多種文件格式,包括PDF、PNG、HTML、TIFF、GIF、JPEG、IMAGE和BITMAP,允許多樣化的文件列印選項。

哪些平台支援使用.NET C# 庫列印文件?

該庫支援多個平台,如Windows、macOS、iOS和Android,確保跨這些作業系統的一致和可靠的列印能力。

在.NET C#中,靜默列印與基於對話框的列印有何不同?

靜默列印允許通過PrintSilently()方法進行程式化的文件列印,而無需使用者互動。基於對話框的列印涉及顯示一個列印對話框以進行使用者自訂,通過PrintWithDialog()方法實現。

Can IronPrint perform grayscale printing and adjust the number of copies programmatically?

Yes, you can set custom print settings such as enabling grayscale and specifying the number of copies directly within your C# code using IronPrint's `PrintSettings` class.

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備好開始了嗎?

Nuget Downloads 46,090版本:2026.9剛剛發布

立即獲取免費

立即獲取 30天試用金鑰

bullet_checked無需信用卡或註冊帳號
bullet_test在生產
環境中進行測試,且不顯示浮水印
bullet_calendar30 天全
功能產品
bullet_support試用期間提供 24/5 技術
支援
立即獲取您的免費30天試用金鑰
不需要信用卡或帳戶建立
C# NuGet PDF程式庫
安裝方法NuGet

版本: 2026.9

PM > Install-Package IronPrint
nuget.org/packages/IronPrint/
  1. 在解決方案資源管理器中,右鍵點擊引用,管理NuGet套件
  2. 選擇瀏覽並搜尋"IronPrint"
  3. 選擇套件並安裝
C# PDF DLL
下載DLL

版本: 2026.9

  1. 下載並解壓IronPrint到比如~/Libs這樣的位置在您的Solution目錄下
  2. 在Visual Studio解決方案資源管理器中,右鍵點擊引用。選擇瀏覽,"IronPrint.dll"

授權從$999

有問題嗎?聯繫我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預約您的免費
現場演示
Booking Badge

全球數百萬工程師信賴

Iron Software的客戶標誌
獲得非義務性諮詢
完成下列表單或發郵件到sales@ironsoftware.com
您的資訊將始終保密。
全球數百萬工程師信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立