打印文檔教程
IronPrint 是一個強大的打印庫,旨在幫助 .NET C# 開發人員將打印功能集成到他們的應用程序中。IronPrint 擁有廣泛的兼容性譜,跨越 Windows、macOS、iOS 和 Android 平台,並能在多種操作系統上穩定、可靠地運行。無論您是在為桌面環境、Apple 的 macOS 生態系統,還是移動平台如 iOS 和 Android 創建應用程序,IronPrint 簡化了打印功能的實施,為您的 .NET C# 環境中的所有打印需求提供了一個多功能且用戶友好的解決方案。
目錄
安裝與 NuGet
Install-Package IronPrint
立即開始在您的專案中使用IronPDF,並享受免費試用。
查看 IronPrint 上 Nuget 快速安裝和部署。已被下載超過800萬次,它正用C#改變。
Install-Package IronPrint
列印文件
靜音列印
無需顯示列印對話框即可無縫列印文件。列印設置可以直接在代碼中完成。
:path=/static-assets/print/content-code-examples/tutorials/print-document-print-silently.cs
using IronPrint;
// Print the document
Printer.Print("newDoc.pdf");
Imports IronPrint
' Print the document
Printer.Print("newDoc.pdf")
顯示對話框列印
啟動列印過程時顯示列印設置對話框。這允許使用者互動地自訂列印選項。
:path=/static-assets/print/content-code-examples/tutorials/print-document-print-with-dialog.cs
using IronPrint;
// Show print dialog
Printer.ShowPrintDialog("newDoc.pdf");
Imports IronPrint
' Show print dialog
Printer.ShowPrintDialog("newDoc.pdf")
應用列印設定
以程式方式調整列印設定以符合特定需求。本節提供通過程式碼微調列印配置的功能。
:path=/static-assets/print/content-code-examples/tutorials/print-document-apply-print-setting.cs
using IronPrint;
// Configure print setting
PrintSettings printSettings = new PrintSettings();
printSettings.Dpi = 150;
printSettings.NumberOfCopies = 2;
printSettings.PaperOrientation = PaperOrientation.Portrait;
// Print the document
Printer.Print("newDoc.pdf", printSettings);
Imports IronPrint
' Configure print setting
Private printSettings As New PrintSettings()
printSettings.Dpi = 150
printSettings.NumberOfCopies = 2
printSettings.PaperOrientation = PaperOrientation.Portrait
' Print the document
Printer.Print("newDoc.pdf", printSettings)
獲取印表機資訊
獲取印表機名稱
存取所有可用印表機的清單。檢索系統上安裝的印表機名稱,用於資訊目的或在您的應用程式中進行動態印表機選擇。
:path=/static-assets/print/content-code-examples/tutorials/print-document-get-printer-names.cs
using IronPrint;
using System;
using System.Collections.Generic;
// Retrieve printers' name
List<string> printersName = Printer.GetPrinterNames();
foreach (var printer in printersName)
{
Console.WriteLine(printer);
}
Imports IronPrint
Imports System
Imports System.Collections.Generic
' Retrieve printers' name
Private printersName As List(Of String) = Printer.GetPrinterNames()
For Each printer In printersName
Console.WriteLine(printer)
Next printer