跳過到頁腳內容
使用 IRONPRINT

使用 IronPDF 在 C# 中打印 PDF 文件

IronPdf NuGet Package and press Enter. ```shell :ProductInstall ``` NuGet 套件的安裝如下所示:
「安裝

安裝 NuGet 套件

## 列印 PDF 檔案中的 C#;。 現在,讓我們考慮一個範例來說明如何使用 IronPDF Library 在 C# 中列印 PDF 檔案。 開啟 `Program.cs` 檔案。在 `Program.cs` 檔案的頂端加入以下命名空間,以使用 IronPDF: ```csharp using IronPdf; ``` 現在,在 `Main` 函式內寫入以下 [code](https://ironpdf.com/how-to/csharp-print-pdf/#install-ironpdf-for-c-print-to-pdf) 內容: ```csharp using System; // Required for Console operations class Program { static void Main() { // Load the PDF document from file using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf"); // Print the loaded PDF document to the default printer pdfDocument.Print(); // Print operation success message to console Console.WriteLine("File Printed Successfully!"); Console.ReadKey(); } } ``` 讓我們了解程式碼 - 以下程式碼將 PDF 檔案載入記憶體。 "Sample.Pdf "是檔案名稱,D Drive 是我的檔案位置。 您必須寫出完整的檔案路徑以及檔案名稱。 ```csharp using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf"); ``` - `Print()` 函式會使用您的預設印表機列印載入的檔案。

測試程式

Console

Console

在 C# 中列印多個 PDF 文件;

「14

14 PDF files

執行解決方案: Console

Console

將 URL 轉換為 PDF,然後將其列印:執行程式: 「螢幕上顯示的輸出」

螢幕上顯示的輸出

變更印表機名稱:執行程式: Csharp Print Pdf Files 10 related to 測試程式</h4

按>

Console
</div

<hr>

在 C# 中列印多個 PDF 文件;</h2...

Csharp Print Pdf Files 11 related to 測試程式</h4

按>

Console
</div

<hr>

在 C# 中列印多個 PDF 文件;</h2...

Csharp Print Pdf Files 12 related to 測試程式</h4

按>

Console
</div

<hr>

在 C# 中列印多個 PDF 文件;</h2...

常見問題解答

如何使用 IronPDF 在 C# 中列印 PDF 文件?

要在 C# 中使用 IronPDF 列印 PDF 文件,請使用 PdfDocument.FromFile 方法加載 PDF 文檔,然後對加載的文檔調用 Print 方法。

IronPDF 能否按順序列印多個 PDF 文件?

可以,IronPDF 可以通過遍歷文件路徑集合並對每個文檔調用 Print 方法來列印多個 PDF 文件。

如何在 C# 中將 URL 轉換為 PDF 並列印?

使用 IronPDF,通過 HtmlToPdf.RenderUrlAsPdf 方法將 URL 轉換為 PDF,然後對生成的 PDF 文檔使用 Print 方法進行列印。

能否選擇特定打印機來使用 IronPDF 列印 PDF?

可以,您可以在使用 PdfDocument 類的 GetPrintDocument 方法時,通過在 PrinterSettings 對象中設置 PrinterName 屬性來選擇特定的打印機。

IronPDF 支持哪些平台的 PDF 列印?

IronPDF 支持在 .NET Framework、.NET Core 和 .NET 5 和 6 的應用程式上進行 PDF 列印,並與 Windows、macOS、Android 和 iOS 平台兼容。

如何開始使用 .NET 庫在 C# 中列印 PDF?

要開始使用 IronPDF 列印 PDF,請通過 Visual Studio 中的 NuGet 套件管理器安裝此庫,並遵循 Iron Software 提供的文檔和範例。

使用 PDF 分享文檔的好處是什麼?

PDF 具有重量輕、在不同設備中保持一致格式並被大多數操作系統支持的優點。

我是否需要高級 C# 技能才能使用 IronPDF 進行列印?

使用 IronPDF 進行列印任務只需基本的 C# 知識,因為該庫提供簡單的方法和示例以幫助開發人員。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

相關文章