產品比較 A Comparison between IronPDF & iText7 Curtis Chau 更新:2025年11月1日 下載 IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 一個好用且簡單的 PDF 處理工具可以簡化建立和編輯 PDF 文件涉及的許多任務和流程。 在 .NET 生態系統中,有兩個流行的程式庫——IronPDF和 iText——可以在不依賴任何 Adobe 的情況下產生 PDF 文件。 它們都提供了創建、編輯、轉換等多種功能,但本文將重點放在三個標準對這兩個庫進行比較:它們提供的功能、它們提供的文件品質以及這些公司對其產品採用的定價政策。 IronPDF 和 iText 概述 IronPDF 是一個優秀的 .NET PDF 庫,它允許程式設計師輕鬆建立、修改 PDF 文件並與之互動。 它可在不同的 .NET 環境中使用,包括 Core、8、7、6 和 Framework,使其能夠高度靈活地滿足各種開發需求。 IronPDF的主要特點是其豐富的功能集,例如 HTML 轉 PDF、PDF 合併、PDF 加密和數位簽名等。 文件編寫得簡單易懂,使用者可以輕鬆理解,而且該庫本身也擁有強大的技術支援。 iText 是 Java 和 .NET (C#) 上最受歡迎的 PDF 函式庫之一。 iText Core 8 提供企業級可程式解決方案,用於建立和操作 PDF 檔案。 iText 支援多種不同的功能,並以開源 (AGPL) 授權和商業授權兩種方式發布。 這意味著憑藉其多功能性,它能夠涵蓋數位轉型專案中的各種應用場景。 跨平台相容性 IronPDF和iText相容於多種平台; 它們可以在許多不同的系統和 .NET 框架內處理 PDF 檔案。 以下我們將對每款產品支援的框架和平台進行比較。 IronPDF: IronPDF支援的平台概述:IronPDF支援多種平台和環境,確保在各種系統中無縫整合和部署: .NET 版本: .NET Core(8、7、6、5 和 3.1+) .NET Standard (2.0+) .NET Framework (4.6.2+) -應用環境: IronPDF 可在 Windows、Linux、Mac、Docker、Azure 和 AWS 等應用程式環境中運作。 IDE:可與 Microsoft Visual Studio、JetBrains Rider 和 ReSharper 等 IDE 搭配使用。 -作業系統與處理器:支援多種不同的作業系統和處理器,包括 Windows、Mac、Linux、x64、x86、ARM。 iText .NET 版本: .NET Core(2.x、3.x) .NET Framework (4.6.1+) .NET 5+ -應用程式環境: iText 支援多種應用程式環境,因為它同時支援 Java 和 .NET (C#),包括 Windows、Mac、Linux 和 Docker。 -作業系統:可在 Windows、macOS 和 Linux 作業系統上運作。 主要功能比較:IronPDF 與 iText IronPDF 主要功能清單和 iText 都提供了一系列用於處理 PDF 文件的功能和工具。 下一節的重點將是更仔細地研究其中的一些特性,看看這兩個函式庫在執行不同的 PDF 相關任務時有何異同。 IronPDF HTML 轉 PDF 轉換:支援 HTML、CSS、JavaScript 和圖片。 PDF 文件操作:拆分和合併文件、更改格式以及編輯現有 PDF 文件。 -安全性: PDF 加密和解密。 -編輯:新增註解、書籤和大綱。 -範本:套用頁首、頁尾和頁碼。 -浮水印:輕鬆地將文字和圖像浮水印新增至 PDF 檔案; 使用HTML/CSS實現完全控制。 PDF 加蓋:使用 IronPDF 將圖像和文字加蓋到 PDF 文件上。 有關 IronPDF 提供的豐富功能集的更多信息,請訪問IronPDF 功能頁面。 iText PDF 建立:支援從頭開始建立 PDF 文件。 -表單:建立和編輯 PDF 表單。 -數位簽章:簽署 PDF 文件。 -壓縮:優化 PDF 檔案大小。 -內容提取:從 PDF 中提取文字和圖像。 -開源:根據 AGPL 授權提供。 -可自訂性:針對高級用例提供高度可自訂性。 IronPDF 與 iText 的 PDF 功能特性比較 HTML 轉 PDF 使用 IronPDF 將 HTML 內容轉換為 PDF是許多不同辦公室和工作場所都會執行的任務。 下面的程式碼範例比較了 IronPDF 和 iText 處理此過程的方式。 IronPDF using IronPdf; // Configure security settings Installation.EnableWebSecurity = true; // Instantiate Renderer var renderer = new ChromePdfRenderer(); // Create a PDF from an HTML string using C# var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>"); pdf.SaveAs("output.pdf"); // Advanced Example with HTML Assets // Load external HTML assets: images, CSS and JavaScript. var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\"); myAdvancedPdf.SaveAs("html-with-assets.pdf"); using IronPdf; // Configure security settings Installation.EnableWebSecurity = true; // Instantiate Renderer var renderer = new ChromePdfRenderer(); // Create a PDF from an HTML string using C# var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>"); pdf.SaveAs("output.pdf"); // Advanced Example with HTML Assets // Load external HTML assets: images, CSS and JavaScript. var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\"); myAdvancedPdf.SaveAs("html-with-assets.pdf"); $vbLabelText $csharpLabel iText using iText.Html2pdf; static void Main(string[] args) { using (FileStream htmlSource = File.Open("input.html", FileMode.Open)) using (FileStream pdfDest = File.Open("output.pdf", FileMode.Create)) { ConverterProperties converterProperties = new ConverterProperties(); HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties); } } using iText.Html2pdf; static void Main(string[] args) { using (FileStream htmlSource = File.Open("input.html", FileMode.Open)) using (FileStream pdfDest = File.Open("output.pdf", FileMode.Create)) { ConverterProperties converterProperties = new ConverterProperties(); HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties); } } $vbLabelText $csharpLabel 將 HTML 轉換為 PDF 時, IronPDF提供了一個簡潔方便的工具來完成這項任務。 IronPDF 利用 ChromePdfRenderer 將 HTML 內容轉換為 PDF,在為使用者提供像素級完美的 PDF 文件方面表現出色。 使用者可以直接從 HTML 字串建立 PDF,或包含外部資源(例如圖像),並可選擇指定基本路徑,如進階範例所示。 另一方面, iText採用了一種基本方法,使用其 HtmlConverter 類別從 HTML 文件建立 PDF 文件。 加密 PDF 文件 在許多工作場所,使用 IronPDF 對 PDF 文件進行加密和解密至關重要。 下面,我們將看到 iText 和 IronPDF 如何處理 PDF 加密。 IronPDF using IronPdf; using System; // Open an Encrypted File, alternatively create a new PDF from HTML var pdf = PdfDocument.FromFile("encrypted.pdf", "password"); // Edit file metadata pdf.MetaData.Author = "Satoshi Nakamoto"; pdf.MetaData.Keywords = "SEO, Friendly"; pdf.MetaData.ModifiedDate = DateTime.Now; // Edit file security settings pdf.SecuritySettings.RemovePasswordsAndEncryption(); pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key"); pdf.SecuritySettings.AllowUserAnnotations = false; pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserFormData = false; pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights; // Change or set the document encryption password pdf.Password = "my-password"; pdf.SaveAs("secured.pdf"); using IronPdf; using System; // Open an Encrypted File, alternatively create a new PDF from HTML var pdf = PdfDocument.FromFile("encrypted.pdf", "password"); // Edit file metadata pdf.MetaData.Author = "Satoshi Nakamoto"; pdf.MetaData.Keywords = "SEO, Friendly"; pdf.MetaData.ModifiedDate = DateTime.Now; // Edit file security settings pdf.SecuritySettings.RemovePasswordsAndEncryption(); pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key"); pdf.SecuritySettings.AllowUserAnnotations = false; pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserFormData = false; pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights; // Change or set the document encryption password pdf.Password = "my-password"; pdf.SaveAs("secured.pdf"); $vbLabelText $csharpLabel iText using System; using System.IO; using System.Text; using iText.Kernel.Pdf; public class EncryptPdf { public static readonly String DEST = "results/sandbox/security/encrypt_pdf.pdf"; public static readonly String SRC = "../../../resources/pdfs/hello.pdf"; public static readonly String OWNER_PASSWORD = "World"; public static readonly String USER_PASSWORD = "Hello"; public static void Main(String[] args) { FileInfo file = new FileInfo(DEST); file.Directory.Create(); new EncryptPdf().ManipulatePdf(DEST); } protected void ManipulatePdf(String dest) { PdfDocument document = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest, new WriterProperties().SetStandardEncryption( Encoding.UTF8.GetBytes(USER_PASSWORD), Encoding.UTF8.GetBytes(OWNER_PASSWORD), EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128 | EncryptionConstants.DO_NOT_ENCRYPT_METADATA ))); document.Close(); } } using System; using System.IO; using System.Text; using iText.Kernel.Pdf; public class EncryptPdf { public static readonly String DEST = "results/sandbox/security/encrypt_pdf.pdf"; public static readonly String SRC = "../../../resources/pdfs/hello.pdf"; public static readonly String OWNER_PASSWORD = "World"; public static readonly String USER_PASSWORD = "Hello"; public static void Main(String[] args) { FileInfo file = new FileInfo(DEST); file.Directory.Create(); new EncryptPdf().ManipulatePdf(DEST); } protected void ManipulatePdf(String dest) { PdfDocument document = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest, new WriterProperties().SetStandardEncryption( Encoding.UTF8.GetBytes(USER_PASSWORD), Encoding.UTF8.GetBytes(OWNER_PASSWORD), EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128 | EncryptionConstants.DO_NOT_ENCRYPT_METADATA ))); document.Close(); } } $vbLabelText $csharpLabel IronPDF為使用者提供了一種簡單直接的方式來加密 PDF 文件,同時也賦予使用者許多控制權,例如編輯元資料和調整安全設置,例如將文件設為唯讀或限制使用者操作,如複製和貼上。 另一方面, iText採用了一種較低且耗時更長的方法,即在建立文件期間應用 PDF 加密,指定所有者和使用者密碼以及列印權限等權限,並使用 AES-128 等加密標準。 編輯 PDF 內容 有時,在處理機密或私人資訊時,可能需要使用 IronPDF 對 PDF 文件中的部分文字進行編輯。以下程式碼範例將示範如何使用 IronPDF 編輯文本,並與 iText 進行比較。 IronPDF using IronPdf; PdfDocument pdf = PdfDocument.FromFile("novel.pdf"); // Redact 'are' phrase from all pages pdf.RedactTextOnAllPages("are"); pdf.SaveAs("redacted.pdf"); using IronPdf; PdfDocument pdf = PdfDocument.FromFile("novel.pdf"); // Redact 'are' phrase from all pages pdf.RedactTextOnAllPages("are"); pdf.SaveAs("redacted.pdf"); $vbLabelText $csharpLabel iText using System; using System.IO; using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; using iText.Kernel.Colors; string src = "input.pdf"; string dest = "output_redacted.pdf"; using (PdfReader reader = new PdfReader(src)) using (PdfWriter writer = new PdfWriter(dest)) using (PdfDocument pdfDoc = new PdfDocument(reader, writer)) { // Iterate through each page for (int pageNum = 1; pageNum <= pdfDoc.GetNumberOfPages(); pageNum++) { PdfPage page = pdfDoc.GetPage(pageNum); PdfCanvas canvas = new PdfCanvas(page); Rectangle[] rectanglesToRedact = { new Rectangle(100, 100, 200, 50) }; // Define rectangles to redact // Overlay black rectangles to simulate redaction foreach (Rectangle rect in rectanglesToRedact) { canvas.SetFillColor(ColorConstants.BLACK) .Rectangle(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()) .Fill(); } } } using System; using System.IO; using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; using iText.Kernel.Colors; string src = "input.pdf"; string dest = "output_redacted.pdf"; using (PdfReader reader = new PdfReader(src)) using (PdfWriter writer = new PdfWriter(dest)) using (PdfDocument pdfDoc = new PdfDocument(reader, writer)) { // Iterate through each page for (int pageNum = 1; pageNum <= pdfDoc.GetNumberOfPages(); pageNum++) { PdfPage page = pdfDoc.GetPage(pageNum); PdfCanvas canvas = new PdfCanvas(page); Rectangle[] rectanglesToRedact = { new Rectangle(100, 100, 200, 50) }; // Define rectangles to redact // Overlay black rectangles to simulate redaction foreach (Rectangle rect in rectanglesToRedact) { canvas.SetFillColor(ColorConstants.BLACK) .Rectangle(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()) .Fill(); } } } $vbLabelText $csharpLabel IronPDF 的編輯工具簡潔易用,只需幾行程式碼即可簡化編輯流程。 這有助於提高 PDF 編輯任務的效率,並為使用者提供一種簡單的方法來保護其敏感和私人資料的安全。 另一方面, iText並沒有像 IronPDF 那樣提供內建的編輯工具。 但是,它仍然可以使用上述方法覆蓋敏感數據,以覆蓋用戶希望編輯的內容。 這可能會導致一些問題,因為這些矩形實際上並沒有刪除或正確地編輯文本,這意味著其他人可能會複製和貼上被編輯的資料。 簽署PDF文檔 使用IronPDF 對 PDF 文件進行數位簽章可以節省時間,尤其是在實現自動化流程時。 以下是一些程式碼片段,比較了 IronPDF 與 iText 在執行文件數位簽章方面的差異。 IronPDF using IronPdf; using IronPdf.Signing; using System.Security.Cryptography.X509Certificates; // Create X509Certificate2 object with X509KeyStorageFlags set to Exportable X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable); // Create PdfSignature object var sig = new PdfSignature(cert); // Sign PDF document PdfDocument pdf = PdfDocument.FromFile("document.pdf"); pdf.Sign(sig); pdf.SaveAs("signed.pdf"); using IronPdf; using IronPdf.Signing; using System.Security.Cryptography.X509Certificates; // Create X509Certificate2 object with X509KeyStorageFlags set to Exportable X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable); // Create PdfSignature object var sig = new PdfSignature(cert); // Sign PDF document PdfDocument pdf = PdfDocument.FromFile("document.pdf"); pdf.Sign(sig); pdf.SaveAs("signed.pdf"); $vbLabelText $csharpLabel iText using System; using System.IO; using iText.Kernel.Pdf; using iText.Signatures; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Pkcs; using Org.BouncyCastle.X509; class Program { static void Main(string[] args) { string src = "input.pdf"; string dest = "output_signed.pdf"; string pfxFile = "your_certificate.pfx"; string pfxPassword = "your_password"; try { // Load your certificate Pkcs12Store ks = new Pkcs12Store(new FileStream(pfxFile, FileMode.Open), pfxPassword.ToCharArray()); string alias = null; foreach (string al in ks.Aliases) { if (ks.IsKeyEntry(al)) { alias = al; break; } } ICipherParameters pk = ks.GetKey(alias).Key; X509CertificateEntry[] chain = ks.GetCertificateChain(alias); X509Certificate2 cert = new X509Certificate2(chain[0].Certificate.GetEncoded()); // Create output PDF with signed content using (PdfReader reader = new PdfReader(src)) using (PdfWriter writer = new PdfWriter(dest)) using (PdfDocument pdfDoc = new PdfDocument(reader, writer)) { // Create the signer PdfSigner signer = new PdfSigner(pdfDoc, writer, new StampingProperties().UseAppendMode()); // Configure signature appearance PdfSignatureAppearance appearance = signer.GetSignatureAppearance(); appearance.SetReason("Digital Signature"); appearance.SetLocation("Your Location"); appearance.SetContact("Your Contact"); // Create signature IExternalSignature pks = new PrivateKeySignature(pk, "SHA-256"); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CMS); } Console.WriteLine($"PDF digitally signed successfully: {dest}"); } catch (Exception ex) { Console.WriteLine($"Error signing PDF: {ex.Message}"); } } } using System; using System.IO; using iText.Kernel.Pdf; using iText.Signatures; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Pkcs; using Org.BouncyCastle.X509; class Program { static void Main(string[] args) { string src = "input.pdf"; string dest = "output_signed.pdf"; string pfxFile = "your_certificate.pfx"; string pfxPassword = "your_password"; try { // Load your certificate Pkcs12Store ks = new Pkcs12Store(new FileStream(pfxFile, FileMode.Open), pfxPassword.ToCharArray()); string alias = null; foreach (string al in ks.Aliases) { if (ks.IsKeyEntry(al)) { alias = al; break; } } ICipherParameters pk = ks.GetKey(alias).Key; X509CertificateEntry[] chain = ks.GetCertificateChain(alias); X509Certificate2 cert = new X509Certificate2(chain[0].Certificate.GetEncoded()); // Create output PDF with signed content using (PdfReader reader = new PdfReader(src)) using (PdfWriter writer = new PdfWriter(dest)) using (PdfDocument pdfDoc = new PdfDocument(reader, writer)) { // Create the signer PdfSigner signer = new PdfSigner(pdfDoc, writer, new StampingProperties().UseAppendMode()); // Configure signature appearance PdfSignatureAppearance appearance = signer.GetSignatureAppearance(); appearance.SetReason("Digital Signature"); appearance.SetLocation("Your Location"); appearance.SetContact("Your Contact"); // Create signature IExternalSignature pks = new PrivateKeySignature(pk, "SHA-256"); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CMS); } Console.WriteLine($"PDF digitally signed successfully: {dest}"); } catch (Exception ex) { Console.WriteLine($"Error signing PDF: {ex.Message}"); } } } $vbLabelText $csharpLabel 以數位方式將簽名套用至 PDF 檔案時, IronPDF提供了一個簡潔而強大的工具來完成此過程。 它的簡單性使得整個過程可以快速完成,從而節省任何將其用於簽名需求的開發人員的時間。 iText需要更長、更複雜的過程才能將數位簽章應用於 PDF 檔案。 雖然使用不同的介面選項和按鍵可以為使用者提供更多控制權,但該工具執行此任務的複雜性可能會阻礙其使用。 在PDF文件中新增浮水印 IronPDF 的 PDF 新增和個人化浮水印功能可以大大幫助保護機密性、版權、品牌推廣或任何涉及敏感資訊的任務。 以下是 IronPDF 和 iText 如何為 PDF 文件添加浮水印的比較。 IronPDF using IronPdf; // Stamps a Watermark onto a new or existing PDF var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center); pdf.SaveAs(@"C:\Path\To\Watermarked.pdf"); using IronPdf; // Stamps a Watermark onto a new or existing PDF var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center); pdf.SaveAs(@"C:\Path\To\Watermarked.pdf"); $vbLabelText $csharpLabel iText using iText.IO.Font; using iText.IO.Font.Constants; using iText.Kernel.Colors; using iText.Kernel.Font; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Canvas; using iText.Kernel.Pdf.Extgstate; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; public class TransparentWatermark { public static readonly String DEST = "results/sandbox/stamper/transparent_watermark.pdf"; public static readonly String SRC = "../../../resources/pdfs/hero.pdf"; public static void Main(String[] args) { FileInfo file = new FileInfo(DEST); file.Directory.Create(); new TransparentWatermark().ManipulatePdf(DEST); } protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfCanvas under = new PdfCanvas(pdfDoc.GetFirstPage().NewContentStreamBefore(), new PdfResources(), pdfDoc); PdfFont font = PdfFontFactory.CreateFont(FontProgramFactory.CreateFont(StandardFonts.HELVETICA)); Paragraph paragraph = new Paragraph("This watermark is added UNDER the existing content") .SetFont(font) .SetFontSize(15); Canvas canvasWatermark1 = new Canvas(under, pdfDoc.GetDefaultPageSize()) .ShowTextAligned(paragraph, 297, 550, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0); canvasWatermark1.Close(); PdfCanvas over = new PdfCanvas(pdfDoc.GetFirstPage()); over.SetFillColor(ColorConstants.BLACK); paragraph = new Paragraph("This watermark is added ON TOP OF the existing content") .SetFont(font) .SetFontSize(15); Canvas canvasWatermark2 = new Canvas(over, pdfDoc.GetDefaultPageSize()) .ShowTextAligned(paragraph, 297, 500, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0); canvasWatermark2.Close(); paragraph = new Paragraph("This TRANSPARENT watermark is added ON TOP OF the existing content") .SetFont(font) .SetFontSize(15); over.SaveState(); PdfExtGState gs1 = new PdfExtGState(); gs1.SetFillOpacity(0.5f); over.SetExtGState(gs1); Canvas canvasWatermark3 = new Canvas(over, pdfDoc.GetDefaultPageSize()) .ShowTextAligned(paragraph, 297, 450, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0); canvasWatermark3.Close(); over.RestoreState(); pdfDoc.Close(); } } using iText.IO.Font; using iText.IO.Font.Constants; using iText.Kernel.Colors; using iText.Kernel.Font; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Canvas; using iText.Kernel.Pdf.Extgstate; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; public class TransparentWatermark { public static readonly String DEST = "results/sandbox/stamper/transparent_watermark.pdf"; public static readonly String SRC = "../../../resources/pdfs/hero.pdf"; public static void Main(String[] args) { FileInfo file = new FileInfo(DEST); file.Directory.Create(); new TransparentWatermark().ManipulatePdf(DEST); } protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfCanvas under = new PdfCanvas(pdfDoc.GetFirstPage().NewContentStreamBefore(), new PdfResources(), pdfDoc); PdfFont font = PdfFontFactory.CreateFont(FontProgramFactory.CreateFont(StandardFonts.HELVETICA)); Paragraph paragraph = new Paragraph("This watermark is added UNDER the existing content") .SetFont(font) .SetFontSize(15); Canvas canvasWatermark1 = new Canvas(under, pdfDoc.GetDefaultPageSize()) .ShowTextAligned(paragraph, 297, 550, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0); canvasWatermark1.Close(); PdfCanvas over = new PdfCanvas(pdfDoc.GetFirstPage()); over.SetFillColor(ColorConstants.BLACK); paragraph = new Paragraph("This watermark is added ON TOP OF the existing content") .SetFont(font) .SetFontSize(15); Canvas canvasWatermark2 = new Canvas(over, pdfDoc.GetDefaultPageSize()) .ShowTextAligned(paragraph, 297, 500, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0); canvasWatermark2.Close(); paragraph = new Paragraph("This TRANSPARENT watermark is added ON TOP OF the existing content") .SetFont(font) .SetFontSize(15); over.SaveState(); PdfExtGState gs1 = new PdfExtGState(); gs1.SetFillOpacity(0.5f); over.SetExtGState(gs1); Canvas canvasWatermark3 = new Canvas(over, pdfDoc.GetDefaultPageSize()) .ShowTextAligned(paragraph, 297, 450, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0); canvasWatermark3.Close(); over.RestoreState(); pdfDoc.Close(); } } $vbLabelText $csharpLabel IronPDF簡單直覺的 API 使用戶能夠快速地將自訂浮水印套用至 PDF 文件,並完全控制整個流程。 它利用 HTML/CSS 進一步簡化了流程,同時又不失任何自訂控制。 iText 為 PDF 添加浮水印的方法需要更多的人工操作,可能會減慢處理速度。 在 PDF 上新增圖像和文字 有時需要在 PDF 頁面上添加文字或圖像,類似於在 PDF 文件上添加浮水印。 接下來,我們將比較 IronPDF 和 iText 在 PDF 文件上新增內容的方式。 IronPDF using IronPdf; using IronPdf.Editing; ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create text stamper TextStamper textStamper = new TextStamper() { Text = "Text Stamper!", FontFamily = "Bungee Spice", UseGoogleFont = true, FontSize = 30, IsBold = true, IsItalic = true, VerticalAlignment = VerticalAlignment.Top, }; // Stamp the text stamper pdf.ApplyStamp(textStamper); pdf.SaveAs("stampText.pdf"); // Create image stamper ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) { VerticalAlignment = VerticalAlignment.Top, }; // Stamp the image stamper pdf.ApplyStamp(imageStamper, 0); pdf.SaveAs("stampImage.pdf"); using IronPdf; using IronPdf.Editing; ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create text stamper TextStamper textStamper = new TextStamper() { Text = "Text Stamper!", FontFamily = "Bungee Spice", UseGoogleFont = true, FontSize = 30, IsBold = true, IsItalic = true, VerticalAlignment = VerticalAlignment.Top, }; // Stamp the text stamper pdf.ApplyStamp(textStamper); pdf.SaveAs("stampText.pdf"); // Create image stamper ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) { VerticalAlignment = VerticalAlignment.Top, }; // Stamp the image stamper pdf.ApplyStamp(imageStamper, 0); pdf.SaveAs("stampImage.pdf"); $vbLabelText $csharpLabel iText using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; public void StampPDF(string inputPdfPath, string outputPdfPath, string stampText) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(inputPdfPath), new PdfWriter(outputPdfPath)); Document doc = new Document(pdfDoc); // Add stamp (text) to each page int numPages = pdfDoc.GetNumberOfPages(); for (int i = 1; i <= numPages; i++) { doc.ShowTextAligned(new Paragraph(stampText), 36, 36, i, iText.Layout.Properties.TextAlignment.LEFT, iText.Layout.Properties.VerticalAlignment.TOP, 0); } doc.Close(); } using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; public void StampPDF(string inputPdfPath, string outputPdfPath, string stampText) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(inputPdfPath), new PdfWriter(outputPdfPath)); Document doc = new Document(pdfDoc); // Add stamp (text) to each page int numPages = pdfDoc.GetNumberOfPages(); for (int i = 1; i <= numPages; i++) { doc.ShowTextAligned(new Paragraph(stampText), 36, 36, i, iText.Layout.Properties.TextAlignment.LEFT, iText.Layout.Properties.VerticalAlignment.TOP, 0); } doc.Close(); } $vbLabelText $csharpLabel IronPDF可以幫助您以靈活且可自訂的方式為 PDF 添加文字或圖像,並提供完全控制。 它的 API 易於理解和使用,尤其對於熟悉 HTML/CSS 的開發人員來說更是如此。 iText使用其圖像和文字圖章工具,使用戶能夠更好地控制 PDF 文件中顯示的內容,儘管這個過程最終可能會更加手動。 將 DOCX 轉換為 PDF 有時,您可能需要將 PDF 檔案從一種格式轉換為另一種格式。 在這種情況下,我們將探討使用 IronPDF 將 DOCX 轉換為 PDF ,以及 IronPDF 和 iText 如何處理此流程的差異。 IronPDF using IronPdf; // Instantiate Renderer DocxToPdfRenderer renderer = new DocxToPdfRenderer(); // Render from DOCX file PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx"); // Save the PDF pdf.SaveAs("pdfFromDocx.pdf"); using IronPdf; // Instantiate Renderer DocxToPdfRenderer renderer = new DocxToPdfRenderer(); // Render from DOCX file PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx"); // Save the PDF pdf.SaveAs("pdfFromDocx.pdf"); $vbLabelText $csharpLabel iText iText 本身無法處理 DOCX 到 PDF 的轉換; 相反,它依賴於 DocX 或 Aspose.Words 等外部函式庫。 IronPDF為開發人員提供了一個簡單明了的工具來處理 DOCX 到 PDF 的轉換任務,無需外部程式庫即可輕鬆將 DOCX 檔案轉換為 PDF 格式。 而iText則依賴外部函式庫來完成這項任務。 程式碼範例比較總結 iText C# HTML 轉 PDF 的替代方案 有關更詳細的範例,請造訪IronPDF 從 HTML 建立 PDF 的範例。 Bootstrap 與現代 CSS 框架支持 在實際開發過程中,經常會出現一個關鍵問題,那就是每個函式庫對現代 CSS 框架的處理能力如何。 Bootstrap、Tailwind CSS 和 Foundation 構成了大多數現代 Web 應用程式的基礎,框架相容性會對您的開發工作流程和輸出品質產生重大影響。 IronPDF:全面支持現代框架 IronPDF 的 Chrome 渲染引擎為所有現代 CSS 框架提供完整、可用於生產環境的支援: Bootstrap 5:所有版面均原生支援 flexbox 和 CSS Grid Tailwind CSS:完全支援實用性優先框架 現代 CSS3:變換、動畫、自訂屬性和進階選擇器 -框架驗證:成功渲染Bootstrap 首頁和Bootstrap 模板 程式碼範例:Bootstrap進度指示器 using IronPdf; var renderer = new ChromePdfRenderer(); string bootstrap ProgressBars = @" <!DOCTYPE html> <html> <head> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> </head> <body> <div class='container my-5'> <h2>Project Progress Dashboard</h2> <div class='mb-4'> <div class='d-flex justify-content-between mb-1'> <span>Backend Development</span> <span class='text-success fw-bold'>85%</span> </div> <div class='progress' style='height: 25px;'> <div class='progress-bar progress-bar-striped bg-success' role='progressbar' style='width: 85%' aria-valuenow='85' aria-valuemin='0' aria-valuemax='100'> </div> </div> </div> <div class='mb-4'> <div class='d-flex justify-content-between mb-1'> <span>Frontend UI</span> <span class='text-warning fw-bold'>60%</span> </div> <div class='progress' style='height: 25px;'> <div class='progress-bar progress-bar-animated bg-warning' role='progressbar' style='width: 60%' aria-valuenow='60' aria-valuemin='0' aria-valuemax='100'> </div> </div> </div> <div class='mb-4'> <div class='d-flex justify-content-between mb-1'> <span>Testing & QA</span> <span class='text-info fw-bold'>40%</span> </div> <div class='progress' style='height: 25px;'> <div class='progress-bar bg-info' role='progressbar' style='width: 40%' aria-valuenow='40' aria-valuemin='0' aria-valuemax='100'> </div> </div> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(bootstrapProgressBars); pdf.SaveAs("project-progress.pdf"); using IronPdf; var renderer = new ChromePdfRenderer(); string bootstrap ProgressBars = @" <!DOCTYPE html> <html> <head> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> </head> <body> <div class='container my-5'> <h2>Project Progress Dashboard</h2> <div class='mb-4'> <div class='d-flex justify-content-between mb-1'> <span>Backend Development</span> <span class='text-success fw-bold'>85%</span> </div> <div class='progress' style='height: 25px;'> <div class='progress-bar progress-bar-striped bg-success' role='progressbar' style='width: 85%' aria-valuenow='85' aria-valuemin='0' aria-valuemax='100'> </div> </div> </div> <div class='mb-4'> <div class='d-flex justify-content-between mb-1'> <span>Frontend UI</span> <span class='text-warning fw-bold'>60%</span> </div> <div class='progress' style='height: 25px;'> <div class='progress-bar progress-bar-animated bg-warning' role='progressbar' style='width: 60%' aria-valuenow='60' aria-valuemin='0' aria-valuemax='100'> </div> </div> </div> <div class='mb-4'> <div class='d-flex justify-content-between mb-1'> <span>Testing & QA</span> <span class='text-info fw-bold'>40%</span> </div> <div class='progress' style='height: 25px;'> <div class='progress-bar bg-info' role='progressbar' style='width: 40%' aria-valuenow='40' aria-valuemin='0' aria-valuemax='100'> </div> </div> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(bootstrapProgressBars); pdf.SaveAs("project-progress.pdf"); $vbLabelText $csharpLabel iText7:框架支援有限 iText7 使用自訂的 HTML 轉換 PDF 轉換器 (pdfHTML),但此轉換器對現代 CSS 框架有許多限制: -無法執行 JavaScript:無法處理動態 Bootstrap 元件 Flexbox 支援有限: Bootstrap 4+ 佈局經常無法正確渲染(v7.1.15 僅部分支援) -不支援 CSS Grid:現代基於網格的佈局將無法正常工作。 -需要手動預處理:複雜的佈局需要使用 Selenium 或 Puppeteer 等外部工具。 根據iText 官方文檔,建議開發者: 避免使用複雜的 CSS 佈局,包括 Flexbox。 使用基於表格的佈局,而不是現代網格系統 將 Bootstrap 元件簡化為基本 HTML 由於框架相容性有限,請進行全面測試。 實際影響:如果您的應用程式使用 Bootstrap 作為其使用者介面,並且您需要匯出與 Web 設計相符的 PDF,則 iText7 需要對 HTML/CSS 進行大量重新設計才能產生 PDF,或者需要與外部瀏覽器自動化工具集成,這將大大增加複雜性和開發時間。 有關全面的 CSS 框架相容性信息,請參閱Bootstrap 和 Flexbox CSS 指南。 定價與許可:IronPDF 與 iText Library 的比較 IronPDF定價和許可 IronPDF 許可選項提供不同級別的許可和附加功能供您購買。 開發者還可以購買Iron Suite ,以兩款產品的價格獲得 Iron Software 的所有產品。 如果您尚未準備好購買許可證,IronPDF 提供 30 天的免費試用版。 -永久許可證:根據您的團隊規模、專案需求和地點數量,提供一系列永久許可證。 每種許可證類型都包含電子郵件支援服務。 Lite 許可證:此許可證支援一個開發者、一個地點和一個專案。 Plus License:支援三名開發者、三個地點和三個項目,價格為$1,199 。 Plus 許可證提供聊天、電話和電子郵件支援。 -專業許可證:適用於較大的團隊,支援十名開發人員、十個地點和十個項目,價格為$2,399 。 它提供與前幾個層級相同的聯絡支援管道,但也提供螢幕共享支援。 -免版稅再分發: IronPDF 的許可還提供免版稅再分發保障,只需額外支付$2,399即可。 -不間斷的產品支援:每年只需支付$1,199即可獲得持續的產品更新、安全功能升級以及工程團隊的支持,或一次性購買$2,399即可獲得 5 年的保障。 Iron Suite:只需$1,498 ,即可存取所有 Iron Software 產品,包括 IronPDF、IronOCR、IronWord、IronXL、IronBarcode、IronQR、IronZIP、IronPrint 和 IronWebScraper。 IronPDF 許可比較 iText 許可 AGPL 授權: iText Core 函式庫是開源的,使用者可以免費使用。 要根據此授權模式使用 iText,使用者必須遵守其條款,並且根據此授權對 iText 進行的任何修改也必須根據 AGPL 授權模式發布。 -商業許可: iText 為專案不符合 AGPL 條款的開發者提供商業許可模式,價格根據報價而定。 文件與支援:IronPDF 與 iText 的比較 IronPDF -全面的文件:涵蓋所有功能的詳盡且用戶友好的文件。 24/5 支援:提供線上工程師支援。 -影片教學: YouTube 上提供逐步影片指南。 -社群論壇:活躍的社群成員可獲得更多支援。 -定期更新:每月進行產品更新,包含最新功能和安全性修補程式。 iText -文件:涵蓋 iText 軟體功能的詳細文件。 -範例和教學:各種功能的教學和程式碼範例。 GitHub:開發者可以將任何問題或錯誤提交到 iText GitHub 儲存庫,並與 iText 團隊溝通。 -更新: iText 提供定期更新和改進。 有關 IronPDF 文件和支援的更多詳細信息,請訪問IronPDF 文件和Iron Software YouTube 頻道。 結論 在 .NET 的 PDF 處理工具領域,IronPDF 和 iText 都提供了強大的功能,滿足各種開發需求。 IronPDF 的優點在於其與 .NET Core、Framework 和 Standard 等平台的直接集成,以及 HTML 轉 PDF 等全面功能和進階安全性選項。 另一方面,以其 Java 血統而聞名的 iText 提供強大的 PDF 生成和處理工具,並提供開源和商業許可,強調多功能性和可自訂性。 最終選擇哪種工具取決於專案要求、許可偏好以及所需的技術支援等級。 無論是選擇 IronPDF 的簡潔性和靈活性,還是選擇開源 PDF 庫 iText 的豐富功能集,開發人員都有充足的資源來有效簡化應用程式中的 PDF 工作流程。 您可以嘗試30 天免費試用,以了解其可用功能。 請注意iText 是其各自所有者的註冊商標。 本網站與iText沒有任何關聯,也未獲得iText的認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 文中比較僅供參考,反映的是撰寫本文時可公開取得的資訊。 常見問題解答 如何在 C# 中將 HTML 轉換為 PDF? 您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字串轉換成 PDF。您也可以使用 RenderHtmlFileAsPdf 將 HTML 檔案轉換成 PDF。 IronPDF 與 iText 的主要差異為何? IronPdf 因其易用性、全面的說明文件和強大的技術支援而備受稱讚,是開發人員的友善選擇。iText 雖然功能強大,但通常需要較多的手動工作,並有開放原始碼 (AGPL) 和商業授權。 PDF 函式庫有哪些授權選項? IronPdf 提供各種永久授權和免權利金選項,而 iText 則提供免費的 AGPL 授權,並針對不符合 AGPL 的專案提供商業選項。 哪個 PDF 函式庫能為開發人員提供更好的支援? IronPdf 提供全面的文件、24/5 工程師支援和活躍的社群論壇,確保開發人員能取得最新的資源和協助。 IronPDF 兼容不同的 .NET 環境嗎? 是的,IronPDF 與 .NET Core、.NET Standard 和 .NET Framework 相容,並可在 Windows、Linux、Mac、Docker、Azure 和 AWS 等環境下運作。 IronPDF 如何處理 PDF 加密? IronPdf 提供直接的 API 來加密 PDF,讓使用者可以輕鬆編輯元資料和調整安全性設定,確保文件的安全性與合規性。 IronPDF 可以執行 DOCX 至 PDF 的轉換嗎? 是的,IronPDF 在 DOCX 到 PDF 的轉換方面非常出色,它提供了一個直接而高效的過程,不需要外部庫,簡化了應用程式中的文件轉換任務。 哪些功能使 IronPDF 在 HTML 到 PDF 的轉換中脫穎而出呢? IronPDF 利用 ChromePdfRenderer 進行 HTML 至 PDF 的轉換,可輕鬆整合 HTML、CSS 和 JavaScript,確保網頁內容精確地呈現成 PDF。 IronPDF 和 iText 的跨平台兼容性如何? 這兩個函式庫都支援多種作業系統和環境,但 IronPDF 在 HTML 轉換為 PDF 和 PDF 加密等任務上提供了更簡化的體驗。 IronPDF 提供哪些主要功能? IronPDF 提供的功能包括 HTML 到 PDF 的轉換、PDF 檔案操作、加密和解密、編輯功能、水印、PDF 圖章和數位簽章。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 相關文章 發表日期 2026年1月20日 Generate PDF Using iTextSharp in MVC vs IronPDF: A Complete Comparison Compare PDF generation methods in ASP.NET MVC using iTextSharp vs IronPDF. Discover which library offers better HTML rendering and easier implementation. 閱讀更多 更新2026年1月7日 Ghostscript GPL vs IronPDF: Technical Comparison Guide Discover the key differences between Ghostscript GPL and IronPDF. Compare AGPL licensing vs commercial, command-line switches vs native .NET API, and HTML-to-PDF capabilities. 閱讀更多 更新2026年1月21日 Which ASP.NET PDF Library Offers the Best Value for .NET Core Development? Discover the best PDF library for ASP.NET Core applications. Compare IronPDF's Chrome engine with Aspose and Syncfusion alternatives. 閱讀更多 A Comparison between IronPDF and TextcontrolA Comparison between IronPDF and Wi...
發表日期 2026年1月20日 Generate PDF Using iTextSharp in MVC vs IronPDF: A Complete Comparison Compare PDF generation methods in ASP.NET MVC using iTextSharp vs IronPDF. Discover which library offers better HTML rendering and easier implementation. 閱讀更多
更新2026年1月7日 Ghostscript GPL vs IronPDF: Technical Comparison Guide Discover the key differences between Ghostscript GPL and IronPDF. Compare AGPL licensing vs commercial, command-line switches vs native .NET API, and HTML-to-PDF capabilities. 閱讀更多
更新2026年1月21日 Which ASP.NET PDF Library Offers the Best Value for .NET Core Development? Discover the best PDF library for ASP.NET Core applications. Compare IronPDF's Chrome engine with Aspose and Syncfusion alternatives. 閱讀更多