如何在C#中設置列印時的份數

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

列印多份文件是一個常見需求——需要原件和複本的發票、大批列印的運送標籤、或者需要向多個部門分發的報告。 而不是在迴圈中調用Print()並為每份複件建立單獨的列印工作,正確的方法是設置一次份數,讓列印驅動在單一作業中處理複件。

IronPrint的PrintSettings.NumberOfCopies屬性接受一個整數,並在一次操作中將指定的份數發送到列印機。 我們在下方涵蓋安裝、基本使用、非同步工作流程和組合設置。

快速入門:設置份數

  1. 透過NuGet安裝IronPrint:Install-Package IronPrint
  2. 新增using IronPrint;到文件
  3. 建立一個PrintSettings物件
  4. 設定NumberOfCopies為所需的份數
  5. 使用文件路徑將設置傳遞給Printer.Print()
  1. 使用NuGet套件管理器安裝https://www.nuget.org/packages/IronPrint

    PM > Install-Package IronPrint
  2. 複製並運行這段程式碼片段。

    using IronPrint;
    
    // Print 3 copies of a PDF in one print job
    PrintSettings settings = new PrintSettings();
    settings.NumberOfCopies = 3;
    Printer.Print("invoice.pdf", settings);
  3. 部署以在您的實時環境中測試

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

    arrow pointer

PrintSettings.NumberOfCopies NumberOfCopies 1 0 NumberOfCopies PrintSettings NumberOfCopies NumberOfCopies PrintSettings.NumberOfCopies

如何設置無訊息列印的複本數?

無訊息列印將文件直接發送到列印機,不會顯示對話框。 我們透過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)
$vbLabelText   $csharpLabel

列印驅動在硬體層面接收複本指令,這比排隊五個單獨的作業更快更可靠。 這在共用網路列印機上很重要,當單獨的作業可能與其他使用者的文件交錯。

若未顯式設置,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)
$vbLabelText   $csharpLabel

對於非阻塞工作流程,將相同的Printer.Print()

複本數在平台間是否有局限性?

在某些平台上,列印驅動可能無法復製PrintSettings.NumberOfCopies中指定的確切數量。 IronPrint文件指出,受限於平台特定的限制,可能導致值被忽略,導致單一複本。 這是一個驅動層的限制,而不是IronPrint的限制。

在Windows桌面應用程式中——大多數列印工作流的主要目標,PrintSettings.NumberOfCopies在本地和網路列印機上均準確無誤。 如果您發現列印機持續忽略設置,請確認其驅動支持透過Windows的列印機屬性面板的整理多份作業。

我的下一步是什麼?

我們涵蓋了如何使用PrintSettings.NumberOfCopies設置列印份數,展示了無訊息列印和異步列印,將複本數與其他設置結合,並指出了平台特定的注意事項。

進一步閱讀,請瀏覽這些資源:

獲取免費試用授權以在真實環境中測試所有功能,或者當您準備好部署時查看授權選項

常見問題

如何使用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並將其功能實作於您的應用程式中。

Curtis Chau
技術作家

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

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備好開始了嗎?
Nuget 下載 44,051 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

仍在滾動?

想要快速證明嗎? PM > Install-Package IronPrint
運行範例 看看您的文件如何到達印表機。