產品比較 在編輯PDF方面iTextSharp與IronPDF之間的比較 Curtis Chau 更新:2026年1月18日 下載 IronPDF NuGet 下載 DLL 下載 Windows Installer 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 Full Comparison Looking for a detailed feature-by-feature breakdown? See how IronPDF stacks up against Itext on pricing, HTML support, and licensing. View Full Comparison PDF(便攜式文件格式)是一種廣泛使用的文件格式,因其能夠保持文件格式、安全性和便攜性而廣受歡迎。 PDF 文件已成為世界上使用最廣泛的文件格式之一,並且有多個庫可用於在 C# 語言中建立和操作 PDF。 了解如何使用IronPDF和 iTextSharp 透過 C# 編輯 PDF 文件,利用這些強大的庫使這項任務變得簡單。 在本文中,我們將比較 C# 中兩個流行的 PDF 處理庫:iTextSharp 和IronPDF。 我們將討論如何使用這兩個函式庫編輯 PDF 文件,然後我們將探討IronPDF與 iTextSharp 相比有哪些優勢,尤其是在輸出列印、效能和價格方面。 iTextSharp DLL 與IronPDF庫簡介 iTextSharp 和IronPDF 的功能和試用資訊可以幫助開發人員在 C# 中有效地處理 PDF 文件。 這兩個庫都提供了建立、編輯和操作 PDF 文件的各種特性和功能。 iTextSharp DLL 是基於 Java 的 iText 函式庫的 C# 移植版。 它提供了一個簡單易用的 API,用於建立和操作 PDF 文件。 iTextSharp 是一個開源函式庫,採用 AGPL 授權。 IronPDF是一個.NET函式庫,旨在以 C# 建立、編輯和操作 PDF 檔案。 它提供了一個現代化且直觀的 API,用於處理 PDF 文件。 IronPDF是一個商業庫,提供免費試用版和訂閱選項,以滿足更廣泛的需求。 iTextSharp 和IronPDF庫的比較 iTextSharp 和IronPDF庫都提供了廣泛的功能和功能,用於建立、編輯和操作 PDF 文件。 然而, IronPDF比 iTextSharp 有幾個優勢,這使得它成為在 C# 中處理 PDF 文件的首選。 使用 iTextSharp 和IronPDF編輯 PDF 文件 現在我們已經討論了 iTextSharp 和IronPDF之間的區別,接下來讓我們看看如何使用這兩個庫來編輯 PDF 文件。 我們將透過範例示範如何使用 iTextSharp 和IronPDF在現有 PDF 文件中新增文字、表單欄位和填寫表單。 使用 iTextSharp 編輯 PDF 文件 先決條件 開始之前,您需要準備以下物品: 您的電腦上已安裝 Visual Studio。 具備 C# 程式語言的基礎知識。 您的專案中已安裝 iTextSharp 庫。 要將 iTextSharp 庫安裝到您的專案中,您可以使用NuGet套件管理器。 開啟 Visual Studio 項目,然後在解決方案資源管理器中以滑鼠右鍵按一下專案名稱。 從上下文選單中選擇"管理NuGet套件"。 在NuGet套件管理器中,搜尋"iTextSharp",並安裝該套件的最新版本。 建立新的 PDF 文件 要使用 iTextSharp 建立新的 PDF 文件,我們需要建立一個"Document"類別的新實例,並將一個新的 FileStream 物件傳遞給其建構函數。 舉個例子: using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; using System.IO; // Create a new PDF document using (var writer = new PdfWriter(new FileStream("newfile.pdf", FileMode.Create))) { using (var pdf = new PdfDocument(writer)) { var document = new Document(pdf); // Create a header paragraph Paragraph header = new Paragraph("HEADER") .SetTextAlignment(TextAlignment.CENTER) .SetFontSize(16); // Add the header to the document document.Add(header); // Loop through pages and align header text for (int i = 1; i <= pdf.GetNumberOfPages(); i++) { Rectangle pageSize = pdf.GetPage(i).GetPageSize(); float x = pageSize.GetWidth() / 2; float y = pageSize.GetTop() - 20; // Add the header text to each page document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); } // Set the margins document.SetTopMargin(50); document.SetBottomMargin(50); } } using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; using System.IO; // Create a new PDF document using (var writer = new PdfWriter(new FileStream("newfile.pdf", FileMode.Create))) { using (var pdf = new PdfDocument(writer)) { var document = new Document(pdf); // Create a header paragraph Paragraph header = new Paragraph("HEADER") .SetTextAlignment(TextAlignment.CENTER) .SetFontSize(16); // Add the header to the document document.Add(header); // Loop through pages and align header text for (int i = 1; i <= pdf.GetNumberOfPages(); i++) { Rectangle pageSize = pdf.GetPage(i).GetPageSize(); float x = pageSize.GetWidth() / 2; float y = pageSize.GetTop() - 20; // Add the header text to each page document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); } // Set the margins document.SetTopMargin(50); document.SetBottomMargin(50); } } $vbLabelText $csharpLabel 在上面的程式碼中,我們建立了一個名為"newfile.pdf"的新PDF文件,並在其中添加了一個段落標題。 編輯現有PDF文件 要使用 iTextSharp 編輯現有的 PDF 文件,您需要一個 PdfReader 物件來讀取現有的 PDF 文檔,還需要一個 PdfStamper 物件來修改它。 舉個例子: using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; using iText.Html2pdf; using System.IO; /** * iText URL to PDF * anchor-itext-url-to-pdf **/ private void ExistingWebURL() { // Initialize PDF writer PdfWriter writer = new PdfWriter("wikipedia.pdf"); // Initialize PDF document using PdfDocument pdf = new PdfDocument(writer); ConverterProperties properties = new ConverterProperties(); properties.SetBaseUri("https://en.wikipedia.org/wiki/Portable_Document_Format"); // Convert HTML to PDF Document document = HtmlConverter.ConvertToDocument( new FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties); // Create and add a header paragraph Paragraph header = new Paragraph("HEADER") .SetTextAlignment(TextAlignment.CENTER) .SetFontSize(16); document.Add(header); // Align header text for each page for (int i = 1; i <= pdf.GetNumberOfPages(); i++) { Rectangle pageSize = pdf.GetPage(i).GetPageSize(); float x = pageSize.GetWidth() / 2; float y = pageSize.GetTop() - 20; // Add header text aligned at the top document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); } // Set the top and bottom margins document.SetTopMargin(50); document.SetBottomMargin(50); document.Close(); } using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; using iText.Html2pdf; using System.IO; /** * iText URL to PDF * anchor-itext-url-to-pdf **/ private void ExistingWebURL() { // Initialize PDF writer PdfWriter writer = new PdfWriter("wikipedia.pdf"); // Initialize PDF document using PdfDocument pdf = new PdfDocument(writer); ConverterProperties properties = new ConverterProperties(); properties.SetBaseUri("https://en.wikipedia.org/wiki/Portable_Document_Format"); // Convert HTML to PDF Document document = HtmlConverter.ConvertToDocument( new FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties); // Create and add a header paragraph Paragraph header = new Paragraph("HEADER") .SetTextAlignment(TextAlignment.CENTER) .SetFontSize(16); document.Add(header); // Align header text for each page for (int i = 1; i <= pdf.GetNumberOfPages(); i++) { Rectangle pageSize = pdf.GetPage(i).GetPageSize(); float x = pageSize.GetWidth() / 2; float y = pageSize.GetTop() - 20; // Add header text aligned at the top document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); } // Set the top and bottom margins document.SetTopMargin(50); document.SetBottomMargin(50); document.Close(); } $vbLabelText $csharpLabel 在這段程式碼中,會開啟一個現有的 PDF 文件,並為其頁面添加標題,同時保持文字對齊方式正確。 使用IronPDF編輯 PDF 文檔 IronPDF是一個功能強大的 C# PDF 庫,可以輕鬆編輯 PDF 文件。 本教學將逐步介紹如何使用IronPDF編輯現有 PDF 文件,包括建立新的 PDF 文件、新增頁面、合併 PDF 等。 先決條件 請確保您已具備: Visual Studio IDE IronPDF庫 步驟 1:建立新項目 在 Visual Studio 中建立一個新的 C# 專案。 選擇"控制台應用程式"項目類型。 步驟 2:安裝IronPDF 使用NuGet套件管理器將IronPDF庫安裝到您的專案中。 // Execute this command in the Package Manager Console Install-Package IronPdf // Execute this command in the Package Manager Console Install-Package IronPdf SHELL 步驟 3:載入現有 PDF 文檔 使用 PdfDocument 類別載入現有 PDF 文件: using IronPdf; // Path to an existing PDF file var existingPdf = @"C:\path\to\existing\pdf\document.pdf"; // Load the PDF document var pdfDoc = PdfDocument.FromFile(existingPdf); using IronPdf; // Path to an existing PDF file var existingPdf = @"C:\path\to\existing\pdf\document.pdf"; // Load the PDF document var pdfDoc = PdfDocument.FromFile(existingPdf); $vbLabelText $csharpLabel 步驟 4:為現有 PDF 文件新增頁面 新增頁面: // Add a new page with default size var newPage = pdfDoc.AddPage(); newPage.Size = PageSize.Letter; // Add a new page with default size var newPage = pdfDoc.AddPage(); newPage.Size = PageSize.Letter; $vbLabelText $csharpLabel 步驟五:從網站建立 PDF 直接從網頁URL產生PDF文件。 舉個例子: using IronPdf; /** * IronPDF URL to PDF * anchor-ironpdf-website-to-pdf **/ private void ExistingWebURL() { // Create PDF from a webpage var Renderer = new IronPdf.ChromePdfRenderer(); // Set rendering options Renderer.RenderingOptions.MarginTop = 50; // millimeters Renderer.RenderingOptions.MarginBottom = 50; Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print; Renderer.RenderingOptions.TextHeader = new TextHeaderFooter() { CenterText = "{pdf-title}", DrawDividerLine = true, FontSize = 16 }; Renderer.RenderingOptions.TextFooter = new TextHeaderFooter() { LeftText = "{date} {time}", RightText = "Page {page} of {total-pages}", DrawDividerLine = true, FontSize = 14 }; Renderer.RenderingOptions.EnableJavaScript = true; Renderer.RenderingOptions.RenderDelay = 500; // milliseconds // Render URL as PDF using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format"); PDF.SaveAs("wikipedia.pdf"); } using IronPdf; /** * IronPDF URL to PDF * anchor-ironpdf-website-to-pdf **/ private void ExistingWebURL() { // Create PDF from a webpage var Renderer = new IronPdf.ChromePdfRenderer(); // Set rendering options Renderer.RenderingOptions.MarginTop = 50; // millimeters Renderer.RenderingOptions.MarginBottom = 50; Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print; Renderer.RenderingOptions.TextHeader = new TextHeaderFooter() { CenterText = "{pdf-title}", DrawDividerLine = true, FontSize = 16 }; Renderer.RenderingOptions.TextFooter = new TextHeaderFooter() { LeftText = "{date} {time}", RightText = "Page {page} of {total-pages}", DrawDividerLine = true, FontSize = 14 }; Renderer.RenderingOptions.EnableJavaScript = true; Renderer.RenderingOptions.RenderDelay = 500; // milliseconds // Render URL as PDF using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format"); PDF.SaveAs("wikipedia.pdf"); } $vbLabelText $csharpLabel iTextSharp 和IronPDF的差別 iTextSharp 是一個流行的開源程式庫,用於在 C# 中建立、操作和提取 PDF 文件中的資料。 它有據可查,並被廣泛應用。 另一方面, IronPDF更現代化,具有更多功能和優勢,使其成為開發人員的更好選擇。 從 HTML 輸入字串產生 PDF 以下是如何使用IronPDF從 HTML 建立 PDF 的方法: using IronPdf; /** * IronPDF HTML to PDF * anchor-ironpdf-document-from-html **/ private void HTMLString() { // Render HTML to PDF var Renderer = new IronPdf.ChromePdfRenderer(); using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>"); Renderer.RenderingOptions.TextFooter = new HtmlHeaderFooter() { HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>" }; var OutputPath = "ChromeHtmlToPdf.pdf"; PDF.SaveAs(OutputPath); } using IronPdf; /** * IronPDF HTML to PDF * anchor-ironpdf-document-from-html **/ private void HTMLString() { // Render HTML to PDF var Renderer = new IronPdf.ChromePdfRenderer(); using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>"); Renderer.RenderingOptions.TextFooter = new HtmlHeaderFooter() { HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>" }; var OutputPath = "ChromeHtmlToPdf.pdf"; PDF.SaveAs(OutputPath); } $vbLabelText $csharpLabel iText 7 HTML 轉 PDF 使用 iText 7 將 HTML 文字轉換為 PDF: using iText.Html2pdf; using System.IO; /** * iText HTML to PDF * anchor-itext-html-to-pdf **/ private void HTMLString() { HtmlConverter.ConvertToPdf("<h1>Hello iText7</h1>", new FileStream("iText7HtmlToPdf.pdf", FileMode.Create)); } using iText.Html2pdf; using System.IO; /** * iText HTML to PDF * anchor-itext-html-to-pdf **/ private void HTMLString() { HtmlConverter.ConvertToPdf("<h1>Hello iText7</h1>", new FileStream("iText7HtmlToPdf.pdf", FileMode.Create)); } $vbLabelText $csharpLabel 表現 IronPDF 的設計目標是比 iTextSharp 更快、更有效率,因此能夠使用更少的資源更快地產生 PDF 檔案。 這種效率對於大型或複雜的文件至關重要。 定價 iTextSharp 某些用途需要商業許可,費用可能較高。而IronPDF則提供更經濟實惠的定價模式,並提供多種選項以滿足不同需求和預算。 授權和定價 iTextSharp 和IronPDF的主要區別之一在於它們的許可和定價模式。 iTextSharp:根據 AGPL 授權協議授權,非開源專案需要商業許可。 商業許可證的費用各不相同。 IronPDF:提供免費試用版和靈活的許可方式,包括開發者許可和伺服器許可,使其適合商業用途。 結論 總之,雖然 iTextSharp 和IronPDF都能在 C# 中處理 PDF 文件,但IronPDF憑藉其更全面的功能和更高的效率脫穎而出。它提供了更高級的功能、更直覺的 API 和更優異的效能。 其靈活的定價方式使其適用於商業項目和大型組織。 IronPDF 具有卓越的 HTML 轉 PDF 功能,開發人員可以輕鬆產生包含富媒體或互動式內容的報告或文件。 IronPDF價格實惠,對於需要強大且高效的 C# 專案 PDF 庫的開發人員來說,它是一個絕佳的選擇。 請注意iTextSharp 是其各自所有者的註冊商標。 本網站與iTextSharp無任何關聯,亦未獲得其認可或贊助。所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供參考,反映的是撰寫本文時可公開取得的資訊。 常見問題解答 如何在C#中編輯PDF文件而不丟失格式? 您可以使用IronPDF在C#中編輯PDF文件,確保格式保留。IronPDF提供先進的功能和現代的API,用於高效的PDF操作。 安裝PDF庫在Visual Studio中有哪些步驟? 要在Visual Studio中安裝像IronPDF這樣的PDF庫,打開NuGet包管理器,搜索IronPDF,然後安裝包到您的項目中。 如何在C#中將網頁URL轉換為PDF? IronPDF允許您使用ChromePdfRenderer類將網頁URL轉換為PDF,確保高品質輸出。 iTextSharp和IronPDF在授權方面有何不同? iTextSharp在AGPL下授權,對於非開源項目需要商業授權,而IronPDF提供靈活的授權選項,包括免費試用。 如何使用C#向現有PDF添加文本? 通過IronPDF,您可以使用像AddText這樣的方法在PdfDocument對象上向現有PDF添加文本,實現無縫PDF編輯。 使用IronPDF相比iTextSharp有什麼優勢? IronPDF提供更好的性能、現代的API和靈活的定價。它還提供先進的HTML到PDF的轉換和更好的輸出質量,使其成為C#中PDF編輯的首選。 開始在C#項目中使用IronPDF需要什麼? 您需要Visual Studio IDE和通過NuGet包管理器安裝的IronPDF庫以開始在您的C#項目中使用IronPDF。 我可以在C#中從HTML字符串創建PDF嗎? 可以,IronPDF允許使用RenderHtmlAsPdf等方法從HTML字符串創建PDF,提供一個強大的HTML到PDF轉換工具。 是什麼讓IronPDF成為C#開發者的多用途工具? IronPDF的直觀API、高效表現、先進的HTML到PDF轉換以及具有成本效益的定價使其成為C#開發者的多用途工具。 開發人員如何確保C#中的高質量PDF輸出? 通過使用IronPDF,開發人員可以確保高質量的PDF輸出,因為其先進的渲染引擎和全面的功能集專為專業PDF操作而設計。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 更新2026年3月1日 在 ASP.NET MVC 中生成 PDF:iTextSharp vs IronPDF 指南 比較在 ASP.NET MVC 中使用 iTextSharp vs IronPDF 的 PDF 產生方法。發現哪個函式庫能提供更好的 HTML 呈現以及更容易的實作。 閱讀更多 更新2026年2月1日 Ghostscript GPL vs IronPDF:技術比較指南 探索 Ghostscript GPL 與 IronPDF 的主要差異。比較 AGPL 授權與商業授權、指令列開關與本機 .NET API,以及 HTML-to-PDF 功能。 閱讀更多 更新2026年3月1日 ASP PDF 庫:比較 IronPDF、Aspose 和 Syncfusion 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多 從字節數組創建PDF C# iTextSharp(vs IronPDF)什麼是iText?(C#和Java PDF...
更新2026年3月1日 在 ASP.NET MVC 中生成 PDF:iTextSharp vs IronPDF 指南 比較在 ASP.NET MVC 中使用 iTextSharp vs IronPDF 的 PDF 產生方法。發現哪個函式庫能提供更好的 HTML 呈現以及更容易的實作。 閱讀更多
更新2026年2月1日 Ghostscript GPL vs IronPDF:技術比較指南 探索 Ghostscript GPL 與 IronPDF 的主要差異。比較 AGPL 授權與商業授權、指令列開關與本機 .NET API,以及 HTML-to-PDF 功能。 閱讀更多
更新2026年3月1日 ASP PDF 庫:比較 IronPDF、Aspose 和 Syncfusion 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多