如何在C#中設置列印時的份數
列印多份文件是一個常見需求——需要原件和複本的發票、大批列印的運送標籤、或者需要向多個部門分發的報告。 而不是在迴圈中調用Print()並為每份複件建立單獨的列印工作,正確的方法是設置一次份數,讓列印驅動在單一作業中處理複件。
IronPrint的PrintSettings.NumberOfCopies屬性接受一個整數,並在一次操作中將指定的份數發送到列印機。 我們在下方涵蓋安裝、基本使用、非同步工作流程和組合設置。
快速入門:設置份數
- 透過NuGet安裝IronPrint:
Install-Package IronPrint - 新增
using IronPrint;到文件 - 建立一個
PrintSettings物件 - 設定
NumberOfCopies為所需的份數 - 使用文件路徑將設置傳遞給
Printer.Print()
PrintSettings.NumberOfCopies
NumberOfCopies
1
0
NumberOfCopies
PrintSettings
NumberOfCopies
NumberOfCopies
PrintSettings.NumberOfCopies
最小化工作流程(5 步驟)
- 安裝 IronPrint C# 列印程式庫
- 建立一個
PrintSettings物件 - 將
NumberOfCopies設定為所需的份數 - 將設置傳遞給
Printer.Print() - 確認列印機輸出正確的份數
如何設置無訊息列印的複本數?
無訊息列印將文件直接發送到列印機,不會顯示對話框。 我們透過PrintSettings.NumberOfCopies配置複本數,並將設置傳遞給Printer.Print():
:path=/static-assets/print/content-code-examples/how-to/set-number-of-copies/set-number-of-copies-silent-copies.cs
using IronPrint;
// Configure the print job for 5 copies
PrintSettings settings = new PrintSettings
{
NumberOfCopies = 5
};
// Print the shipping label
Printer.Print("shipping-label.pdf", settings);
Imports IronPrint
' Configure the print job for 5 copies
Dim settings As New PrintSettings With {
.NumberOfCopies = 5
}
' Print the shipping label
Printer.Print("shipping-label.pdf", settings)
列印驅動在硬體層面接收複本指令,這比排隊五個單獨的作業更快更可靠。 這在共用網路列印機上很重要,當單獨的作業可能與其他使用者的文件交錯。
若未顯式設置,1。 接受任何正整數——將其設置為0或負值沒有實際效果,驅動將回退至單一複本。
如何將複本數與其他列印設置結合?
PrintSettings.NumberOfCopies是一個屬性。 我們可以將其與紙張邊距、紙張尺寸、方向、DPI、灰階模式以及列印機選擇組合在一個配置物件中:
:path=/static-assets/print/content-code-examples/how-to/set-number-of-copies/set-number-of-copies-combined-settings.cs
using IronPrint;
// Configure 3 copies with landscape A4 at 300 DPI
PrintSettings settings = new PrintSettings
{
NumberOfCopies = 3,
PaperSize = PaperSize.A4,
PaperOrientation = PaperOrientation.Landscape,
Dpi = 300,
PaperMargins = new Margins(15),
Grayscale = false,
PrinterName = "HP LaserJet Pro MFP M428"
};
// Print the Q4 report
Printer.Print("Q4-report.pdf", settings);
Imports IronPrint
' Configure 3 copies with landscape A4 at 300 DPI
Dim settings As New PrintSettings With {
.NumberOfCopies = 3,
.PaperSize = PaperSize.A4,
.PaperOrientation = PaperOrientation.Landscape,
.Dpi = 300,
.PaperMargins = New Margins(15),
.Grayscale = False,
.PrinterName = "HP LaserJet Pro MFP M428"
}
' Print the Q4 report
Printer.Print("Q4-report.pdf", settings)
對於非阻塞工作流程,將相同的Printer.Print()。
複本數在平台間是否有局限性?
在某些平台上,列印驅動可能無法復製PrintSettings.NumberOfCopies中指定的確切數量。 IronPrint文件指出,受限於平台特定的限制,可能導致值被忽略,導致單一複本。 這是一個驅動層的限制,而不是IronPrint的限制。
在Windows桌面應用程式中——大多數列印工作流的主要目標,PrintSettings.NumberOfCopies在本地和網路列印機上均準確無誤。 如果您發現列印機持續忽略設置,請確認其驅動支持透過Windows的列印機屬性面板的整理多份作業。
我的下一步是什麼?
我們涵蓋了如何使用PrintSettings.NumberOfCopies設置列印份數,展示了無訊息列印和異步列印,將複本數與其他設置結合,並指出了平台特定的注意事項。
進一步閱讀,請瀏覽這些資源:
- IronPrint教程——列印文件提供端到端列印指導。
- 列印設置使用說明涵蓋邊距、DPI、方向等。
- PrintSettings類API參考提供完整屬性文件。
- Printer類API參考提供所有靜態列印方法。
常見問題
如何使用IronPrint在C#中列印多份文件?
您可以透過在IronPrint中設定'NumberOfCopies'屬性來在C#中列印多份文件,這使得控制列印文件的數量變得容易。
IronPrint支援靜默列印嗎?
是的,IronPrint支援靜默列印,可在不需要使用者互動的情況下列印文件,非常適合自動化工作流程。
我可以用IronPrint在C#中進行非同步列印嗎?
IronPrint提供對非同步工作流程的支援,允許您非同步列印文件,這有助於提升應用程式性能。
可以使用IronPrint組合不同的列印設定嗎?
IronPrint讓您能結合多種列印設定,包括份數、紙張大小及方向,提供靈活的列印解決方案。
使用IronPrint進行多份列印有哪些好處?
使用IronPrint進行多份列印簡化了過程,只需調整單一屬性,支援靜默與非同步列印,並提供可自定義的設置。
我需要安裝額外的軟體來使用IronPrint嗎?
IronPrint是一個.NET程式庫,可以直接整合到您的C#應用程式中,無需為列印任務安裝額外的軟體。
IronPrint如何處理大型列印任務?
IronPrint支援非同步操作,能高效管理大型列印任務,讓您的應用程式在列印時能繼續處理其他任務。
IronPrint是否相容不同的印表型號?
IronPrint專為相容各種印表型號而設計,提供多樣化的列印解決方案以適應不同環境。
我可以用IronPrint自定義列印品質嗎?
可以的,IronPrint允許您自定義列印品質設置,確保您可以按照特定需求調整輸出。
使用IronPrint需要什麼程式知識?
建議具備基本的C#和.NET知識,以有效使用IronPrint並將其功能實作於您的應用程式中。

