產品比較 Itextsharp 和 IronPDF 之間的 C# 中的 PDF 打印比較 Curtis Chau 更新:9月 1, 2025 下載 IronPrint NuGet 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 IronPrint是 Iron Software 全新推出的 .NET 列印庫,相容於包括 Windows、macOS、Android 和 iOS 在內的多種平台。立即開始使用 IronPrint ! 使用 C# 列印 PDF 文件是許多桌面和 Web 應用程式的常見需求。 透過程式設計方式產生和列印 PDF 文件,開發人員在處理文件列印任務時擁有更大的靈活性。 在 C# 中,開發人員可以使用各種函式庫和 API,輕鬆產生和列印 PDF 文件。 無論是列印發票、收據或報告,能夠動態產生 PDF 文件並直接從應用程式列印,都能節省時間和精力。 本文探討如何使用 C# 以及一些可用於此目的的流行函式庫和 API 來列印 PDF。 為此,我們將使用以下程式庫並進行比較。 IronPDF iTextSharp 在本文中,我們將探討如何使用 IronPDF 和 ITextSharp 列印 PDF 文件。這兩者都是高級 PDF 操作 API。 如何使用 iTextSharp 列印 PDF 文件 下載用於解析 PDF 檔案的 C# 庫 透過實例化PdfReader物件載入現有 PDF 文檔 從 PdfReader 實例化PdfDocument對象 從 PdfDocument 實例化PrintHelper對象 在 iTextSharp 中呼叫 PrintHelper 物件的Print方法 1.IronPdf 2. IronPDF是一個功能強大的 C# 庫,它允許開發人員輕鬆建立、操作和處理 PDF 文件。 它提供了一系列功能,使其成為開發人員的熱門選擇,包括將 HTML、CSS 和圖像轉換為 PDF、從頭開始生成 PDF 以及編輯現有 PDF。 IronPDF 也支援各種文件元素,例如圖像、文字、表格和表單,並提供數位簽章、浮水印和加密等進階功能。 它用戶友好的介面和全面的文檔使其成為希望將 PDF 功能整合到其應用程式中的 .NET 開發人員的熱門選擇。 2. iTextSharp iText 是一個流行的開源 PDF 函式庫,開發人員可以使用它在 Java 和 .NET 環境中建立、操作 PDF 文件和從中提取資料。 iTextSharp 是 iText 函式庫在 iText 5 發布後停止維護之前,從原 iText 函式庫移植而來的 .NET 版本。 iText 7 是該庫的最新版本,它完全重寫了原始 iText 庫,提供了更多功能、更好的效能和更強的可擴展性。 iText 7 提供一系列功能,包括 PDF 產生和操作 PDF 文件、數位簽章、表單填寫以及建立 PDF 的支援。 它廣泛應用於金融、法律、政府等各個行業,並以其高品質的產出和靈活性而聞名。 3. 安裝 IronPDF 庫 以下是使用 NuGet 套件管理器安裝 IronPDF 庫的步驟: 開啟 Visual Studio 並建立一個新專案或開啟一個現有專案。 在解決方案資源管理器中以滑鼠右鍵按一下項目,然後選擇"管理 NuGet 套件"。 3.在"NuGet 套件管理員"視窗中,選擇"瀏覽"標籤。 在搜尋欄中輸入"IronPDF",然後按 Enter 鍵。 從搜尋結果中選擇"IronPdf",然後點選"安裝"按鈕。 ! IronPDF NuGet 包搜索 查看將要安裝的依賴項,然後按一下"確定"繼續安裝。 等待安裝完成。 您可以在"輸出"視窗中追蹤進度。 安裝完成後,IronPDF 庫將會加入您的專案中,這樣您就可以開始使用 IronPDF 了。 就是這樣! 您已使用 NuGet 套件管理器成功安裝了 IronPDF。 您也可以直接從 IronPDF 網站下載 IronPDF,或是下載 dll 檔案手動安裝。 4. 安裝 iTextsharp PDF 庫 以下是使用 NuGet 套件管理器安裝 iTextsharp 的步驟: 開啟 Visual Studio,建立一個新專案或開啟一個現有專案。 在解決方案資源管理器中以滑鼠右鍵按一下項目,然後選擇"管理 NuGet 套件"。 3.在"NuGet 套件管理員"視窗中,選擇"瀏覽"標籤。 在搜尋欄中輸入"iTextsharp",然後按 Enter 鍵。 從搜尋結果中選擇"iText 7",然後點選"安裝"按鈕。 查看將要安裝的依賴項,然後按一下"確定"繼續安裝。 等待安裝完成。 您可以在"輸出"視窗中追蹤進度。 安裝完成後,您就可以在專案中使用 iTextsharp 了。 就是這樣! 您已使用 NuGet 套件管理器成功安裝了 iTextsharp。 5. 使用 IronPDF 列印 PDF 文檔 使用 IronPDF 列印 PDF 文件非常簡單,它提供了許多選項,只需幾行程式碼即可列印 PDF 文件。 下面,我們將討論一個程式碼範例,該範例僅使用 IronPDF 的渲染 PDF 物件來列印 IronPDF tiger wiki 頁面,並將指令傳送到預設印表機,而無需任何其他程式庫。 using IronPdf; // Initialize ChromePdfRenderer to render a URL as PDF var renderer = new ChromePdfRenderer(); // Render the PDF from a URL PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); // Print the PDF at 300 DPI to the default printer pdf.Print(300, true); // Get a PrintDocument for additional customization if needed System.Drawing.Printing.PrintDocument printDocYouCanWorkWith = pdf.GetPrintDocument(); using IronPdf; // Initialize ChromePdfRenderer to render a URL as PDF var renderer = new ChromePdfRenderer(); // Render the PDF from a URL PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); // Print the PDF at 300 DPI to the default printer pdf.Print(300, true); // Get a PrintDocument for additional customization if needed System.Drawing.Printing.PrintDocument printDocYouCanWorkWith = pdf.GetPrintDocument(); Imports IronPdf ' Initialize ChromePdfRenderer to render a URL as PDF Private renderer = New ChromePdfRenderer() ' Render the PDF from a URL Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf") ' Print the PDF at 300 DPI to the default printer pdf.Print(300, True) ' Get a PrintDocument for additional customization if needed Dim printDocYouCanWorkWith As System.Drawing.Printing.PrintDocument = pdf.GetPrintDocument() $vbLabelText $csharpLabel 以上程式碼示範如何從 URL 取得數據,IronPDF 使用該 URL 建立 PDF 檔案。然後,程式碼設定印表機參數,並將 PDF 檔案傳送到預設印表機以直接列印該 PDF 文件。 6. 使用 iTextSharp 列印 PDF 文件 使用 iTextSharp 建立 PDF 文件非常容易,但是列印 PDF 文件時,則需要使用其他第三方函式庫。 using iText.Kernel.Pdf; using System.Drawing.Printing; // Method to print a PDF using iTextSharp and another library (e.g., PrintDocument) public void PrintPDF(string filePath) { // Create a PdfReader to read the PDF file PdfReader reader = new PdfReader(filePath); // Create a PdfDocument to interact with the PDF data PdfDocument pdfDoc = new PdfDocument(reader); // Assuming there exists a PrintHelper class that can handle PDF printing PrintHelper printHelper = new PrintHelper(pdfDoc); // Print the PDF document using the helper printHelper.Print(); // Close the PdfDocument to release resources pdfDoc.Close(); } using iText.Kernel.Pdf; using System.Drawing.Printing; // Method to print a PDF using iTextSharp and another library (e.g., PrintDocument) public void PrintPDF(string filePath) { // Create a PdfReader to read the PDF file PdfReader reader = new PdfReader(filePath); // Create a PdfDocument to interact with the PDF data PdfDocument pdfDoc = new PdfDocument(reader); // Assuming there exists a PrintHelper class that can handle PDF printing PrintHelper printHelper = new PrintHelper(pdfDoc); // Print the PDF document using the helper printHelper.Print(); // Close the PdfDocument to release resources pdfDoc.Close(); } Imports iText.Kernel.Pdf Imports System.Drawing.Printing ' Method to print a PDF using iTextSharp and another library (e.g., PrintDocument) Public Sub PrintPDF(ByVal filePath As String) ' Create a PdfReader to read the PDF file Dim reader As New PdfReader(filePath) ' Create a PdfDocument to interact with the PDF data Dim pdfDoc As New PdfDocument(reader) ' Assuming there exists a PrintHelper class that can handle PDF printing Dim printHelper As New PrintHelper(pdfDoc) ' Print the PDF document using the helper printHelper.Print() ' Close the PdfDocument to release resources pdfDoc.Close() End Sub $vbLabelText $csharpLabel 上面的程式碼從指定路徑檢索 PDF 文件,建立一個新的 PDF 文檔對象,然後使用輔助類別將文檔傳送到預設印表機進行列印。 請注意,iTextSharp 本身並不支援列印功能,因此需要額外的第三方程式庫或程式碼來處理實際的列印作業過程。 7.結論 使用 C# 列印 PDF 文件是許多桌面和 Web 應用程式的基本功能。 IronPDF和 iTextSharp 是兩個流行的庫,可以輕鬆建立、操作和列印 PDF 文件。 這兩個庫都提供了一系列功能,包括將 HTML、CSS 和圖像轉換為 PDF,編輯現有 PDF,以及添加數位簽名、浮水印和加密。 IronPDF 以其用戶友好的介面和全面的文件而聞名,使其成為 .NET 開發人員的熱門選擇。 另一方面,iTextSharp 也提供了許多 PDF 功能。 但值得注意的是,它不提供 PDF 列印功能。 為了實現這一目標,我們將不得不使用其他第三方工具。 要了解有關使用 IronPDF 列印 PDF 的更多信息,請訪問以下連結。 如需全面比較 IronPDF 和 iTextSharp,請造訪此連結。 請注意iTextSharp 是其各自擁有者的註冊商標。 本網站與 iTextSharp 無任何關聯、背書或贊助。所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較資料僅供參考,並反映撰寫時的公開資訊。 常見問題解答 如何使用 C# 列印 PDF 檔案? 您可以利用 IronPDF 等函式庫,使用 C# 來列印 PDF 檔案,IronPDF 提供了直接的方法,可以使用其 render PDF 物件將 PDF 傳送至預設印表機。 使用 IronPDF 打印 PDF 有哪些優勢? IronPdf 在列印 PDF 方面具有多項優勢,包括易用性、全面的說明文件,以及可直接列印而無需額外的第三方工具。它還支援各種功能,例如 HTML、CSS 和圖片轉換為 PDF。 如何在 C# 專案中安裝 IronPDF? 要在 C# 專案中安裝 IronPDF,請使用 Visual Studio 中的 NuGet Package Manager。右鍵按一下專案,選擇「管理 NuGet 套件」,搜尋「IronPDF」,然後按一下「安裝」。 iTextSharp 可以在 C# 中直接列印 PDF 嗎? iTextSharp 並不直接支援原生 PDF 列印。它需要額外的第三方函式庫或自訂程式碼來處理列印工作流程。 IronPDF 和 iTextSharp 在處理 PDF 方面的主要差異為何? 主要差異在於 IronPDF 提供直接列印 PDF 的支援,並包含 HTML 至 PDF 轉換和編輯現有 PDF 等功能;而 iTextSharp 雖具彈性並能提供高品質的輸出,但缺乏直接列印支援,需要額外的工具才能實現此功能。 為什麼 PDF 列印在 C# 應用程式中很重要? 在 C# 應用程式中,PDF 列印對於產生發票、收據和報告等工作至關重要。它能讓開發人員製作出具專業外觀的文件,並在不同的平台上維持一致的格式。 IronPDF 列印問題的常見疑難排解步驟是什麼? 常見的故障排除步驟是確保已安裝最新版本的 IronPDF,且專案相依性已正確設定。檢查印表機設定和錯誤記錄也有助於診斷問題。 如何使用 IronPDF 在 C# 中將 HTML 轉換為 PDF? 您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字串轉換為 PDF。此外,也可以使用 RenderHtmlFileAsPdf 方法將 HTML 檔案轉換為 PDF。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 更新6月 22, 2025 IronPrint 與 IronPDF 的比較 探索 IronPrint 和 IronPDF 之間的區別,強調打印功能、平台支持和自定義選項。 閱讀更多 更新8月 20, 2025 PdfiumViewer 在 C# 中打印 PDF(替代教程) PDFiumViewer 是另一個用於在 C# 中處理 PDF 的流行選擇。它建立在開放原始碼專案 PDFium 之上,為其功能提供 .NET 包裝。 閱讀更多 更新8月 20, 2025 如何使用 PDFSharp 打印 PDF 文件 在本文中,我們將在 C# 或 .NET 開發的背景下比較兩個流行的庫,IronPDF 和 PDFSharp 的列印功能。 閱讀更多 IronPrint 與 IronPDF 的比較PdfiumViewer 在 C# 中打印 PDF...
更新8月 20, 2025 PdfiumViewer 在 C# 中打印 PDF(替代教程) PDFiumViewer 是另一個用於在 C# 中處理 PDF 的流行選擇。它建立在開放原始碼專案 PDFium 之上,為其功能提供 .NET 包裝。 閱讀更多
更新8月 20, 2025 如何使用 PDFSharp 打印 PDF 文件 在本文中,我們將在 C# 或 .NET 開發的背景下比較兩個流行的庫,IronPDF 和 PDFSharp 的列印功能。 閱讀更多