IronPrint 教程 打印文件 C# Print Document Tutorial with IronPrint Curtis Chau 更新:2026年1月31日 下載 IronPrint NuGet 下載 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronPrint是一個功能強大的列印庫,旨在幫助.NET C# 開發人員將列印功能整合到他們的應用程式中。 IronPrint具有廣泛的相容性,涵蓋 Windows、macOS、iOS 和 Android 平台,可在各種作業系統上穩定可靠地運作。 無論您是為桌面環境、Apple 的 macOS 生態系統還是 iOS 和 Android 等行動平台創建應用程序, IronPrint都能簡化列印功能的實現,為.NET C# 環境中的所有列印需求提供多功能且用戶友好的解決方案。 快速入門:使用IronPrint靜默列印文件 只需一行程式碼即可列印——無需對話框,輕鬆便捷。 使用 IronPrint.Printer.Print(...) 可以靜默地將 PDF 或影像直接傳送到印表機,使用預設或自訂設定。 使用NuGet套件管理器安裝https://www.nuget.org/packages/IronPrint PM > Install-Package IronPrint 複製並運行這段程式碼。 IronPrint.Printer.Print("path/to/your/document.pdf"); 部署到您的生產環境進行測試 今天就在您的專案中開始使用免費試用IronPrint Free 30 Day Trial 目錄 列印文件 -靜默列印 -帶對話框的列印 -套用列印設定 取得印表機資訊 取得印表機名稱 列印文件 靜默列印 無需顯示列印對話方塊即可無縫列印文件。 然後可以直接在程式碼中設定列印參數。 // 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(); } } // 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(); } } $vbLabelText $csharpLabel 帶對話框的列印 在顯示的列印設定對話方塊中啟動列印過程。 這樣一來,用戶就可以互動式地自訂列印選項。 // 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(); } } // 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(); } } $vbLabelText $csharpLabel 應用程式列印設定 透過程式調整列印設定以滿足特定要求。 本節提供了透過程式碼微調列印配置的功能。 // 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(); } } // 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(); } } $vbLabelText $csharpLabel 取得印表機資訊 取得印表機名稱 查看所有可用印表機的清單。 檢索系統中已安裝印表機的名稱,以便用於資訊參考或在應用程式中進行動態印表機選擇。 // 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); } } } // 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); } } } $vbLabelText $csharpLabel 常見問題解答 如何在 .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() 方法實現。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 38,454 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:38,454 查看許可證 還在捲動嗎? 想要快速證明? PM > Install-Package IronPrint 執行範例 觀看您的文件打到印表機上。 免費 NuGet 下載 總下載量:38,454 查看許可證