IronPrint 入門指南

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

IronPrint:您的 .NET 全方位列印程式庫

IronPrint 是由 Iron Software 開發的列印程式庫。 此函式庫相容於多種環境,包括 Windows、macOS、Android 及 iOS。

相容性

IronPrint 支援以下平台的相容性:

.NET 版本支援

  • C#VB.NETF#
  • .NET 8、7、6、5 及 .NET Core 3.1+
  • .NET Framework (4.6.2+)

支援的作業系統與環境

  • Windows (7 以上版本、Server 2016 以上版本)
  • macOS (10+)
  • iOS (11+)
  • Android API 21+ (v5 "Lollipop")

.NET 專案類型支援

  • 行動裝置 (Xamarin、MAUI 及 Avalonia)
  • 桌面端 (WPF、MAUI 及 Windows Avalonia)
  • 控制台(應用程式與函式庫)

安裝

IronPrint程式庫

透過 NuGet 套件管理員安裝 IronPrint 套件:

dotnet add package IronPrint

您亦可直接從 IronPrint 官方 NuGet 網站下載。

安裝完成後,您只需在 C# 程式碼開頭加入 using IronPrint; 即可開始使用。

套用授權金鑰

接著,請將有效的授權金鑰或試用授權套用至 IronPrint,方法是將授權金鑰指派給 License 類別的 LicenseKey 屬性。 請在 import 語句之後、使用任何 IronPrint 方法之前,加入以下程式碼:

using IronPrint;

// Apply your IronPrint license key here
License.LicenseKey = "your-license-key-here";
using IronPrint;

// Apply your IronPrint license key here
License.LicenseKey = "your-license-key-here";
Imports IronPrint

' Apply your IronPrint license key here
License.LicenseKey = "your-license-key-here"
$vbLabelText   $csharpLabel

程式碼範例

列印文件

只需將檔案路徑傳遞給 Print 方法,即可列印該文件。

using IronPrint;

class Program
{
    static void Main()
    {
        // Specify the file path to be printed
        string filePath = "document.pdf";

        // Invoke the Print method to print the document
        IronPrint.Print(filePath);
    }
}
using IronPrint;

class Program
{
    static void Main()
    {
        // Specify the file path to be printed
        string filePath = "document.pdf";

        // Invoke the Print method to print the document
        IronPrint.Print(filePath);
    }
}
Imports IronPrint

Friend Class Program
	Shared Sub Main()
		' Specify the file path to be printed
		Dim filePath As String = "document.pdf"

		' Invoke the Print method to print the document
		IronPrint.Print(filePath)
	End Sub
End Class
$vbLabelText   $csharpLabel

透過對話方塊列印

using ShowPrintDialog 方法來列印文件,此方法會在列印前顯示列印對話方塊。

using IronPrint;

class Program
{
    static void Main()
    {
        // Specify the file path to be printed
        string filePath = "document.pdf";

        // Invoke the ShowPrintDialog method to prompt the dialog before printing
        IronPrint.ShowPrintDialog(filePath);
    }
}
using IronPrint;

class Program
{
    static void Main()
    {
        // Specify the file path to be printed
        string filePath = "document.pdf";

        // Invoke the ShowPrintDialog method to prompt the dialog before printing
        IronPrint.ShowPrintDialog(filePath);
    }
}
Imports IronPrint

Friend Class Program
	Shared Sub Main()
		' Specify the file path to be printed
		Dim filePath As String = "document.pdf"

		' Invoke the ShowPrintDialog method to prompt the dialog before printing
		IronPrint.ShowPrintDialog(filePath)
	End Sub
End Class
$vbLabelText   $csharpLabel

自訂列印設定

若要透過程式碼設定 PRINT 選項,請建立 PrintSettings 類別的實例。 設定 PrintSettings 物件,並將其傳遞給其中一個 PRINT 方法。

using IronPrint;

class Program
{
    static void Main()
    {
        // Create a PrintSettings object to configure printer settings
        PrintSettings settings = new PrintSettings
        {
            Copies = 2,
            Duplex = DuplexMode.Vertical,
            PageOrientation = PageOrientation.Landscape
        };

        // Specify the file path to be printed
        string filePath = "document.pdf";

        // Invoke the Print method with custom print settings
        IronPrint.Print(filePath, settings);
    }
}
using IronPrint;

class Program
{
    static void Main()
    {
        // Create a PrintSettings object to configure printer settings
        PrintSettings settings = new PrintSettings
        {
            Copies = 2,
            Duplex = DuplexMode.Vertical,
            PageOrientation = PageOrientation.Landscape
        };

        // Specify the file path to be printed
        string filePath = "document.pdf";

        // Invoke the Print method with custom print settings
        IronPrint.Print(filePath, settings);
    }
}
Imports IronPrint

Friend Class Program
	Shared Sub Main()
		' Create a PrintSettings object to configure printer settings
		Dim settings As New PrintSettings With {
			.Copies = 2,
			.Duplex = DuplexMode.Vertical,
			.PageOrientation = PageOrientation.Landscape
		}

		' Specify the file path to be printed
		Dim filePath As String = "document.pdf"

		' Invoke the Print method with custom print settings
		IronPrint.Print(filePath, settings)
	End Sub
End Class
$vbLabelText   $csharpLabel

提供授權與技術支援

IronPrint 是一款付費程式庫; 不過,您亦可在此取得免費試用授權。

如需更多關於 Iron Software 的資訊,請造訪我們的網站:https://ironsoftware.com/ 如需更多支援或有任何疑問,請聯繫我們的團隊

Iron Software 提供支援

如需一般支援或技術諮詢,請透過電子郵件聯絡我們:support@ironsoftware.com/support@ironsoftware.com

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備開始了嗎?
Nuget 下載 41,154 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronPrint
執行範例程式,親眼見證您的文件送印。