跳至頁尾內容
產品比較

IronPDF對比GemBox.Pdf:完整.NET PDF庫比較指南,用於HTML轉PDF轉換

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

IronPDF在其基於Chromium的HTML渲染引擎中表現出色,提供完整的CSS3和JavaScript支持,並內建DOCX轉換功能。 相反,iTextPdf提供了AGPL或商業授權的高級企業功能,但需要外部依賴來支持現代Web標準和文件轉換。

對於處理PDF的開發者來說,擁有一個可靠的PDF生成和操作庫是至關重要的。 .NET生態系統中,有兩個流行的PDF庫脫穎而出——IronPDFiTextPdf——每個都提供有效的工具來建立、編輯和管理PDF文件。 本文基於功能能力、文件質量和定價政策對這些庫進行了深入的比較。

什麼是IronPDF和iTextPdf?

IronPDF如何簡化PDF開發?

IronPDF是一個可靠的.NET庫,用於PDF管理,相容各種.NET環境(Core 8, 7, 6, Framework等)。 它提供了一整套功能集,包括HTML轉PDF合併PDF加密數位簽名。 IronPDF的文件資訊簡單明瞭,使用者可以獲得可靠的技術支援。 開發者經常在Stack Overflow討論中和其他源碼共享平台上找到常見問題的解決方案。 該庫提供API引用以獲得詳細的實施指導,並支持通過NuGet包進行高級安裝方法。 要快速實施,請查看快速入門指南安裝概述以快速開始。

什麼使iTextPdf適合企業應用?

iTextPdf是一個面向企業級文件處理的高級PDF庫,支持Java和.NET(C#)。 提供AGPL和商業授權兩種選擇,能在各種專案需求中靈活運用。 iTextPdf具有高度可定制性,非常適合用於文件加密、數位簽名和表單建立等複雜PDF任務。 該庫在企業環境中非常可靠,提供廣泛的PDF操作功能,並遵循PDF/A標準以便於文件存檔。 需要Section 508無障礙合規的組織通常會選擇支持通用無障礙標準的企業級解決方案。

IronPDF和iTextPdf支持哪些平台?

IronPDF和iTextPdf都支持跨平台功能,使其在.NET中可滿足各種應用需求而具備彈性。 以下是每個庫的相容性細分。

  • .NET版本: 相容.NET Core(8, 7, 6, 5, 3.1+)、.NET Standard(2.0+)和.NET Framework(4.6.2+)。
  • 應用環境: 適用於Windows、Linux、Mac、Docker、Azure和AWS環境。
  • 支持的IDE: 非常適用於Microsoft Visual Studio和JetBrains Rider & ReSharper。
  • 操作系統和處理器: 支持Windows、Mac、Linux、x64、x86、ARM。

  • .NET版本: 相容.NET Core 8, 7, 6, 5, 3.1+、.NET Standard 2.0+、.NET Framework 4.6.2+
  • 應用環境: 適用於Windows、Linux、Mac、Docker、Azure和AWS
  • 支持的IDE: Microsoft Visual Studio和JetBrains Rider & ReSharper
  • 操作系統和處理器: Windows、Mac、Linux、x64、x86、ARM
  • 行動平台通過MAUI支持Android
  • 容器支持遠程容器部署以支持可伸縮的架構

  • .NET版本: 支持.NET Core(2.x, 3.x)、.NET Framework(4.6.1+)和.NET 5+。
  • 應用環境: 相容Windows、macOS、Linux和Docker。

iTextPdf可部署在哪裡?

  • .NET版本: 支持.NET Core 2.x, 3.x, .NET Framework 4.6.1+, .NET 5+
  • 應用環境: 相容Windows、macOS、Linux、Docker
  • 企業部署: 可在伺服器環境中針對AGPL或商業授權進行優化

IronPDF與iTextPdf的主要功能是什麼?

以下是每個庫提供的主要功能的詳細比較。

IronPDF提供了哪些功能?

  • HTML到PDF轉換: 支持HTML、CSS、JavaScript和圖片。
  • PDF操作: 拆分、合併和編輯PDF文件。
  • 安全性: PDF加密和解密功能。
  • 編輯: 允許註釋、書籤和大綱。
  • 模板: 應用頁眉、頁腳和頁碼。
  • 浮水印: 使用HTML/CSS進行控制,支持文字和圖片浮水印。
  • PDF蓋章: 將圖片和文字蓋章新增到PDF文件上。

有關IronPDF功能的更多資訊,請存取IronPDF功能頁面。 該庫還支持從多種來源建立PDF轉換PDF格式,以及使用專業工具組織PDF

iTextPdf提供哪些企業功能?

  • PDF建立: 支持從頭建立PDF文件。
  • 表單: 提供PDF表單的建立和編輯。
  • 數位簽名: 簽署PDF文件。
  • 壓縮: 優化PDF文件大小。
  • 內容提取: 從PDF中提取文字和圖片。
  • 可定制性: 對於複雜項目具有高度可定制性。

兩個庫如何處理HTML到PDF的轉換?

這兩個庫都支持HTML轉PDF,雖然它們的方法和易用性不同。 IronPDF使用Chromium渲染引擎以獲得像素完美的準確性,而iTextPdf使用其pdfHTML附加組件,其CSS支持較有限。 IronPDF支持HTML文件HTML字串URL作為輸入來源,包括完整的JavaScript渲染。 對於復雜佈局,IronPDF可以處理CSS螢幕和列印的媒體型別,並支持自訂邊距以精確控制。

IronPDF

using IronPdf;

// Instantiate the renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from an HTML string
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");

// Advanced example with external assets
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");

// Render with custom options
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
var customPdf = renderer.RenderHtmlAsPdf("<h1>Custom Settings</h1>");
customPdf.SaveAs("custom-settings.pdf");
using IronPdf;

// Instantiate the renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from an HTML string
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");

// Advanced example with external assets
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");

// Render with custom options
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
var customPdf = renderer.RenderHtmlAsPdf("<h1>Custom Settings</h1>");
customPdf.SaveAs("custom-settings.pdf");
Imports IronPdf

' Instantiate the renderer
Dim renderer As New ChromePdfRenderer()

' Create a PDF from an HTML string
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
pdf.SaveAs("output.pdf")

' Advanced example with external assets
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")

' Render with custom options
renderer.RenderingOptions.MarginTop = 50
renderer.RenderingOptions.MarginBottom = 50
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
Dim customPdf = renderer.RenderHtmlAsPdf("<h1>Custom Settings</h1>")
customPdf.SaveAs("custom-settings.pdf")
$vbLabelText   $csharpLabel

iTextPdf

using iText.Html2pdf;
using System.IO;

public class HtmlToPdf
{
    public static void ConvertHtmlToPdf()
    {
        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;
using System.IO;

public class HtmlToPdf
{
    public static void ConvertHtmlToPdf()
    {
        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);
        }
    }
}
Imports iText.Html2pdf
Imports System.IO

Public Class HtmlToPdf
	Public Shared Sub ConvertHtmlToPdf()
		Using htmlSource As FileStream = File.Open("input.html", FileMode.Open)
		Using pdfDest As FileStream = File.Open("output.pdf", FileMode.Create)
			Dim converterProperties As New ConverterProperties()
			HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties)
		End Using
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF提供了HTML到PDF轉換的直觀方法,支持HTML、CSS和JavaScript。 它可以直接從HTML字串中轉換來或包括帶有選擇性基礎路徑的資產。 該庫還支持用於復雜項目和改進渲染的HTML ZIP文件響應式CSS。 對於動態內容,IronPDF提供JavaScript執行渲染延遲選項確保完全載入頁面。 其他渲染功能包括視口控制自定義紙張尺寸。 iTextPdf需要更多的設置,主要集中在基於文件的轉換上,現代網頁標準支持有限。

哪個庫提供更好的PDF加密?

當安全性至關重要時,加密是必不可少的。 以下是每個庫如何處理它。 IronPDF提供完整的安全功能,包括AES加密權限管理。 該庫支持元資料管理清理以刪除可能有害的內容。

IronPDF

using IronPdf;

// Load an encrypted PDF or create a new one
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Set document security settings
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.Password = "my-password";

// Set owner password for administrative access
pdf.SecuritySettings.OwnerPassword = "owner-password";

// Save with encryption
pdf.SaveAs("secured.pdf");
using IronPdf;

// Load an encrypted PDF or create a new one
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Set document security settings
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.Password = "my-password";

// Set owner password for administrative access
pdf.SecuritySettings.OwnerPassword = "owner-password";

// Save with encryption
pdf.SaveAs("secured.pdf");
Imports IronPdf

' Load an encrypted PDF or create a new one
Dim pdf = PdfDocument.FromFile("encrypted.pdf", "password")

' Set document security settings
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint
pdf.SecuritySettings.AllowUserFormData = False
pdf.Password = "my-password"

' Set owner password for administrative access
pdf.SecuritySettings.OwnerPassword = "owner-password"

' Save with encryption
pdf.SaveAs("secured.pdf")
$vbLabelText   $csharpLabel

iTextPdf

using iText.Kernel.Pdf;
using System.Text;

public class EncryptPdf
{
    public static readonly string DEST = "encrypt_pdf.pdf";
    public static readonly string OWNER_PASSWORD = "World";
    public static readonly string USER_PASSWORD = "Hello";

    protected void ManipulatePdf(string dest)
    {
        PdfDocument document = new PdfDocument(new PdfReader("input.pdf"), new PdfWriter(dest,
            new WriterProperties().SetStandardEncryption(
                Encoding.UTF8.GetBytes(USER_PASSWORD),
                Encoding.UTF8.GetBytes(OWNER_PASSWORD),
                EncryptionConstants.ALLOW_PRINTING,
                EncryptionConstants.ENCRYPTION_AES_128)));
        document.Close();
    }
}
using iText.Kernel.Pdf;
using System.Text;

public class EncryptPdf
{
    public static readonly string DEST = "encrypt_pdf.pdf";
    public static readonly string OWNER_PASSWORD = "World";
    public static readonly string USER_PASSWORD = "Hello";

    protected void ManipulatePdf(string dest)
    {
        PdfDocument document = new PdfDocument(new PdfReader("input.pdf"), new PdfWriter(dest,
            new WriterProperties().SetStandardEncryption(
                Encoding.UTF8.GetBytes(USER_PASSWORD),
                Encoding.UTF8.GetBytes(OWNER_PASSWORD),
                EncryptionConstants.ALLOW_PRINTING,
                EncryptionConstants.ENCRYPTION_AES_128)));
        document.Close();
    }
}
Imports iText.Kernel.Pdf
Imports System.Text

Public Class EncryptPdf
	Public Shared ReadOnly DEST As String = "encrypt_pdf.pdf"
	Public Shared ReadOnly OWNER_PASSWORD As String = "World"
	Public Shared ReadOnly USER_PASSWORD As String = "Hello"

	Protected Sub ManipulatePdf(ByVal dest As String)
		Dim document As New PdfDocument(New PdfReader("input.pdf"), New PdfWriter(dest, (New WriterProperties()).SetStandardEncryption(Encoding.UTF8.GetBytes(USER_PASSWORD), Encoding.UTF8.GetBytes(OWNER_PASSWORD), EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128)))
		document.Close()
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF提供了直接的加密和對文件權限的控制。 該庫支持自訂日誌以進行安全審計和授權金鑰管理以進行企業部署。 為了提高安全性,IronPDF提供PDF文件版本控制註冊表配置選項。 iTextPdf需要詳細設置,側重於加密標準。 對於高級安全需求,IronPDF還支持數位簽名與HSM以應對企業需求,以及Kerberos驗證以支持安全環境。

IronPDF和iTextPdf如何處理內容遮蔽?

在PDF文件中遮蔽資訊對於隱私和安全是至關重要的。 以下是每個庫如何支持這一功能。 IronPDF提供完整的遮蔽能力和PDF清理以刪除可能有害的內容。 該庫還提供PDF平面化以將表單和註釋轉換為靜態內容。

IronPDF

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact 'are' from all pages
pdf.RedactTextOnAllPages("are");

// Redact specific text on specific pages
pdf.RedactTextOnPage(0, "confidential");

// Use regular expressions for pattern matching
pdf.RedactTextOnAllPages(@"\b\d{3}-\d{2}-\d{4}\b"); // Redact SSN pattern

pdf.SaveAs("redacted.pdf");
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact 'are' from all pages
pdf.RedactTextOnAllPages("are");

// Redact specific text on specific pages
pdf.RedactTextOnPage(0, "confidential");

// Use regular expressions for pattern matching
pdf.RedactTextOnAllPages(@"\b\d{3}-\d{2}-\d{4}\b"); // Redact SSN pattern

pdf.SaveAs("redacted.pdf");
Imports IronPdf

Dim pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")

' Redact 'are' from all pages
pdf.RedactTextOnAllPages("are")

' Redact specific text on specific pages
pdf.RedactTextOnPage(0, "confidential")

' Use regular expressions for pattern matching
pdf.RedactTextOnAllPages("\b\d{3}-\d{2}-\d{4}\b") ' Redact SSN pattern

pdf.SaveAs("redacted.pdf")
$vbLabelText   $csharpLabel

iTextPdf

using iText.Kernel.Pdf;
using iText.Kernel.Colors;

// Define areas to redact on each page
Rectangle[] rectanglesToRedact = { new Rectangle(100, 100, 200, 50) };

// Draw black rectangles to cover sensitive areas
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader("input.pdf"), new PdfWriter("output_redacted.pdf")))
{
    for (int pageNum = 1; pageNum <= pdfDoc.GetNumberOfPages(); pageNum++)
    {
        PdfPage page = pdfDoc.GetPage(pageNum);
        PdfCanvas canvas = new PdfCanvas(page);
        foreach (Rectangle rect in rectanglesToRedact)
        {
            canvas.SetFillColor(ColorConstants.BLACK)
                  .Rectangle(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight())
                  .Fill();
        }
    }
}
using iText.Kernel.Pdf;
using iText.Kernel.Colors;

// Define areas to redact on each page
Rectangle[] rectanglesToRedact = { new Rectangle(100, 100, 200, 50) };

// Draw black rectangles to cover sensitive areas
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader("input.pdf"), new PdfWriter("output_redacted.pdf")))
{
    for (int pageNum = 1; pageNum <= pdfDoc.GetNumberOfPages(); pageNum++)
    {
        PdfPage page = pdfDoc.GetPage(pageNum);
        PdfCanvas canvas = new PdfCanvas(page);
        foreach (Rectangle rect in rectanglesToRedact)
        {
            canvas.SetFillColor(ColorConstants.BLACK)
                  .Rectangle(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight())
                  .Fill();
        }
    }
}
Imports iText.Kernel.Pdf
Imports iText.Kernel.Colors

' Define areas to redact on each page
Private rectanglesToRedact() As Rectangle = { New Rectangle(100, 100, 200, 50) }

' Draw black rectangles to cover sensitive areas
Using pdfDoc As New PdfDocument(New PdfReader("input.pdf"), New PdfWriter("output_redacted.pdf"))
	Dim pageNum As Integer = 1
	Do While pageNum <= pdfDoc.GetNumberOfPages()
		Dim page As PdfPage = pdfDoc.GetPage(pageNum)
		Dim canvas As New PdfCanvas(page)
		For Each rect As Rectangle In rectanglesToRedact
			canvas.SetFillColor(ColorConstants.BLACK).Rectangle(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()).Fill()
		Next rect
		pageNum += 1
	Loop
End Using
$vbLabelText   $csharpLabel

IronPDF提供了一個方便的遮蔽工具,可輕鬆隱藏所有頁面上的敏感文字。 該庫還提供替換文字功能以更新文件內容,並提供PDF DOM存取以進行詳細的內容操作。 要在遮蔽前提取內容,請使用文字和圖片提取以程式方式解析PDF文件。 iTextPdf需要手動定義和應用黑色矩形以覆蓋敏感區域。 為了完成文件清理,IronPDF還提供PDF清理功能以刪除可能的惡意內容,以及PDF平面化以將互動元素轉換為靜態內容。

哪個庫使數位簽名更容易?

自動執行PDF文件簽名可以節省大量時間。以下是IronPDF和iTextPdf如何處理數位簽名的比較。 IronPDF支持多種簽名方法,包括基於證書的簽名HSM整合。 該庫還維護修訂歷史以追蹤文件更改和簽名有效性。

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)
{
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "Chicago, USA",
    SigningReason = "Document Approval"
};

// Sign PDF document
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
pdf.Sign(sig);

// Apply timestamp
var timestampedSig = new PdfSignature(cert)
{
    TimestampHashAlgorithm = TimestampHashAlgorithm.SHA256,
    TimeStampUrl = "___PROTECTED_URL_245___"
};

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)
{
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "Chicago, USA",
    SigningReason = "Document Approval"
};

// Sign PDF document
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
pdf.Sign(sig);

// Apply timestamp
var timestampedSig = new PdfSignature(cert)
{
    TimestampHashAlgorithm = TimestampHashAlgorithm.SHA256,
    TimeStampUrl = "___PROTECTED_URL_245___"
};

pdf.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates

' Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
Dim cert As New X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable)

' Create PdfSignature object
Dim sig As New PdfSignature(cert) With {
    .SigningContact = "support@ironsoftware.com",
    .SigningLocation = "Chicago, USA",
    .SigningReason = "Document Approval"
}

' Sign PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("document.pdf")
pdf.Sign(sig)

' Apply timestamp
Dim timestampedSig As New PdfSignature(cert) With {
    .TimestampHashAlgorithm = TimestampHashAlgorithm.SHA256,
    .TimeStampUrl = "___PROTECTED_URL_245___"
}

pdf.SaveAs("signed.pdf")
$vbLabelText   $csharpLabel

iTextPdf

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}");
        }
    }
}
Imports System
Imports System.IO
Imports iText.Kernel.Pdf
Imports iText.Signatures
Imports Org.BouncyCastle.Crypto
Imports Org.BouncyCastle.Pkcs
Imports Org.BouncyCastle.X509

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim src As String = "input.pdf"
		Dim dest As String = "output_signed.pdf"
		Dim pfxFile As String = "your_certificate.pfx"
		Dim pfxPassword As String = "your_password"

		Try
			' Load your certificate
			Dim ks As New Pkcs12Store(New FileStream(pfxFile, FileMode.Open), pfxPassword.ToCharArray())
			Dim [alias] As String = Nothing
			For Each al As String In ks.Aliases
				If ks.IsKeyEntry(al) Then
					[alias] = al
					Exit For
				End If
			Next al
			Dim pk As ICipherParameters = ks.GetKey([alias]).Key
			Dim chain() As X509CertificateEntry = ks.GetCertificateChain([alias])
			Dim cert As New X509Certificate2(chain(0).Certificate.GetEncoded())

			' Create output PDF with signed content
			Using reader As New PdfReader(src)
				Using writer As New PdfWriter(dest)
					Using pdfDoc As New PdfDocument(reader, writer)
						' Create the signer
						Dim signer As New PdfSigner(pdfDoc, writer, (New StampingProperties()).UseAppendMode())

						' Configure signature appearance
						Dim appearance As PdfSignatureAppearance = signer.GetSignatureAppearance()
						appearance.SetReason("Digital Signature")
						appearance.SetLocation("Your Location")
						appearance.SetContact("Your Contact")

						' Create signature
						Dim pks As IExternalSignature = New PrivateKeySignature(pk, "SHA-256")
						signer.SignDetached(pks, chain, Nothing, Nothing, Nothing, 0, PdfSigner.CryptoStandard.CMS)
					End Using
				End Using
			End Using
			Console.WriteLine($"PDF digitally signed successfully: {dest}")
		Catch ex As Exception
			Console.WriteLine($"Error signing PDF: {ex.Message}")
		End Try
	End Sub
End Class
$vbLabelText   $csharpLabel

在將數位簽名應用到PDF文件時,IronPDF提供了一種使用X509證書的簡單且高效的方法。 其API簡化了整合但不犧牲安全控制。 IronPDF還支持修訂歷史跟踪以維護文件完整性,並支持多種簽名型別,包括視覺簽名。 該庫與HSM裝置整合以提高安全性並支持證書驗證。 有關安全文件工作流程,請探索簽署並保護PDF功能。 iTextPdf的簽名過程提供了更高的定制選擇,但需要複雜的設置。開發者能夠獲得精細的控制,但在證書處理和簽名配置上面臨更陡峭的學習曲線。

兩個庫如何將浮水印應用到PDF?

在PDF中應用浮水印對於品牌、保密性和版權保護是至關重要的。 以下是IronPDF和iTextPdf如何在PDF文件上應用浮水印。 IronPDF提供靈活的浮水印選項,支持HTML/CSS支持。 該庫還支持背景和前景層以支持複雜的疊加。

IronPDF

using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("___PROTECTED_URL_246___");

// Add text watermark
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);

// Add image watermark
pdf.ApplyWatermark("<img src='logo.png' style='width:200px'>", 45, IronPdf.Editing.VerticalAlignment.Bottom, IronPdf.Editing.HorizontalAlignment.Right);

// Add complex HTML watermark with transparency
string watermarkHtml = @"
<div style='font-size:80px; color:rgba(255,0,0,0.3); font-family:Arial; transform:rotate(-45deg);'>
    CONFIDENTIAL
</div>";
pdf.ApplyWatermark(watermarkHtml, 0, 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("___PROTECTED_URL_246___");

// Add text watermark
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);

// Add image watermark
pdf.ApplyWatermark("<img src='logo.png' style='width:200px'>", 45, IronPdf.Editing.VerticalAlignment.Bottom, IronPdf.Editing.HorizontalAlignment.Right);

// Add complex HTML watermark with transparency
string watermarkHtml = @"
<div style='font-size:80px; color:rgba(255,0,0,0.3); font-family:Arial; transform:rotate(-45deg);'>
    CONFIDENTIAL
</div>";
pdf.ApplyWatermark(watermarkHtml, 0, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);

pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf

' Stamps a Watermark onto a new or existing PDF
Dim renderer As New ChromePdfRenderer()

Dim pdf = renderer.RenderUrlAsPdf("___PROTECTED_URL_246___")

' Add text watermark
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)

' Add image watermark
pdf.ApplyWatermark("<img src='logo.png' style='width:200px'>", 45, IronPdf.Editing.VerticalAlignment.Bottom, IronPdf.Editing.HorizontalAlignment.Right)

' Add complex HTML watermark with transparency
Dim watermarkHtml As String = "
<div style='font-size:80px; color:rgba(255,0,0,0.3); font-family:Arial; transform:rotate(-45deg);'>
    CONFIDENTIAL
</div>"
pdf.ApplyWatermark(watermarkHtml, 0, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)

pdf.SaveAs("C:\Path\To\Watermarked.pdf")
$vbLabelText   $csharpLabel

iTextPdf

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();
    }
}
Imports iText.IO.Font
Imports iText.IO.Font.Constants
Imports iText.Kernel.Colors
Imports iText.Kernel.Font
Imports iText.Kernel.Pdf
Imports iText.Kernel.Pdf.Canvas
Imports iText.Kernel.Pdf.Extgstate
Imports iText.Layout
Imports iText.Layout.Element
Imports iText.Layout.Properties

Public Class TransparentWatermark
	Public Shared ReadOnly DEST As String = "results/sandbox/stamper/transparent_watermark.pdf"
	Public Shared ReadOnly SRC As String = "../../../resources/pdfs/hero.pdf"

	Public Shared Sub Main(ByVal args() As String)
		Dim file As New FileInfo(DEST)
		file.Directory.Create()

		Call (New TransparentWatermark()).ManipulatePdf(DEST)
	End Sub

	Protected Sub ManipulatePdf(ByVal dest As String)
		Dim pdfDoc As New PdfDocument(New PdfReader(SRC), New PdfWriter(dest))
		Dim under As New PdfCanvas(pdfDoc.GetFirstPage().NewContentStreamBefore(), New PdfResources(), pdfDoc)
		Dim font As PdfFont = PdfFontFactory.CreateFont(FontProgramFactory.CreateFont(StandardFonts.HELVETICA))
		Dim paragraph As Paragraph = (New Paragraph("This watermark is added UNDER the existing content")).SetFont(font).SetFontSize(15)

		Dim canvasWatermark1 As Canvas = (New Canvas(under, pdfDoc.GetDefaultPageSize())).ShowTextAligned(paragraph, 297, 550, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0)
		canvasWatermark1.Close()
		Dim over As 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)

		Dim canvasWatermark2 As Canvas = (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()

		Dim gs1 As New PdfExtGState()
		gs1.SetFillOpacity(0.5F)
		over.SetExtGState(gs1)
		Dim canvasWatermark3 As Canvas = (New Canvas(over, pdfDoc.GetDefaultPageSize())).ShowTextAligned(paragraph, 297, 450, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0)
		canvasWatermark3.Close()
		over.RestoreState()

		pdfDoc.Close()
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF的API使浮水印應用快速且靈活,支持HTML和CSS定製。 這種方法創造了視覺上獨特的浮水印而不需要進行廣泛設置。為了更多控制,IronPDF支持背景和前景層以進行複雜的文件疊加,多個浮水印,以及自訂定位。 該庫還提供條碼整合以支持跟蹤目的,並支持SVG圖形支持以支持可擴展的浮水印。 對於高級需求,請探索轉換PDF頁面畫線和矩形的功能。 iTextPdf通過詳細的配置選項允許高度可定製的浮水印放置,雖然需要進行更廣泛的編碼努力。### 哪個庫提供更好的圖像和文字蓋章?

將內容印記到PDF上類似於浮水印,但重點是新增像圖像或文字這樣的特定元素以進行標籤或品牌推广。 以下是IronPDF和iTextPdf如何執行此任務。 IronPDF提供廣泛的印記功能,支持靈活的定位選項。 該庫還支持直接在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,
    HorizontalAlignment = HorizontalAlignment.Center,
    Opacity = 50,
    Rotation = -45
};

// Stamp the text stamper on all pages
pdf.ApplyStamp(textStamper);

// Create HTML stamper for complex layouts
HtmlStamper htmlStamper = new HtmlStamper()
{
    Html = @"<div style='border:2px solid red; padding:10px;'>
             <h3>APPROVED</h3>
             <p>Date: " + DateTime.Now.ToShortDateString() + @"</p>
             </div>",
    VerticalAlignment = VerticalAlignment.Bottom,
    HorizontalAlignment = HorizontalAlignment.Right,
    Width = 200,
    Height = 100
};

pdf.ApplyStamp(htmlStamper);

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("___PROTECTED_URL_247___"))
{
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Left,
    MaxWidth = new Length(150),
    MaxHeight = new Length(150)
};

// Stamp the image stamper on specific pages
pdf.ApplyStamp(imageStamper, new[] { 0, 2, 4 });

pdf.SaveAs("stamped.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,
    HorizontalAlignment = HorizontalAlignment.Center,
    Opacity = 50,
    Rotation = -45
};

// Stamp the text stamper on all pages
pdf.ApplyStamp(textStamper);

// Create HTML stamper for complex layouts
HtmlStamper htmlStamper = new HtmlStamper()
{
    Html = @"<div style='border:2px solid red; padding:10px;'>
             <h3>APPROVED</h3>
             <p>Date: " + DateTime.Now.ToShortDateString() + @"</p>
             </div>",
    VerticalAlignment = VerticalAlignment.Bottom,
    HorizontalAlignment = HorizontalAlignment.Right,
    Width = 200,
    Height = 100
};

pdf.ApplyStamp(htmlStamper);

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("___PROTECTED_URL_247___"))
{
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Left,
    MaxWidth = new Length(150),
    MaxHeight = new Length(150)
};

// Stamp the image stamper on specific pages
pdf.ApplyStamp(imageStamper, new[] { 0, 2, 4 });

pdf.SaveAs("stamped.pdf");
Imports IronPdf
Imports IronPdf.Editing

Dim renderer As New ChromePdfRenderer()

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create text stamper
Dim textStamper As New TextStamper() With {
    .Text = "Text Stamper!",
    .FontFamily = "Bungee Spice",
    .UseGoogleFont = True,
    .FontSize = 30,
    .IsBold = True,
    .IsItalic = True,
    .VerticalAlignment = VerticalAlignment.Top,
    .HorizontalAlignment = HorizontalAlignment.Center,
    .Opacity = 50,
    .Rotation = -45
}

' Stamp the text stamper on all pages
pdf.ApplyStamp(textStamper)

' Create HTML stamper for complex layouts
Dim htmlStamper As New HtmlStamper() With {
    .Html = "<div style='border:2px solid red; padding:10px;'>" &
            "<h3>APPROVED</h3>" &
            "<p>Date: " & DateTime.Now.ToShortDateString() & "</p>" &
            "</div>",
    .VerticalAlignment = VerticalAlignment.Bottom,
    .HorizontalAlignment = HorizontalAlignment.Right,
    .Width = 200,
    .Height = 100
}

pdf.ApplyStamp(htmlStamper)

' Create image stamper
Dim imageStamper As New ImageStamper(New Uri("___PROTECTED_URL_247___")) With {
    .VerticalAlignment = VerticalAlignment.Top,
    .HorizontalAlignment = HorizontalAlignment.Left,
    .MaxWidth = New Length(150),
    .MaxHeight = New Length(150)
}

' Stamp the image stamper on specific pages
pdf.ApplyStamp(imageStamper, {0, 2, 4})

pdf.SaveAs("stamped.pdf")
$vbLabelText   $csharpLabel

iTextPdf

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();
}
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.Layout.Element

Public Sub StampPDF(ByVal inputPdfPath As String, ByVal outputPdfPath As String, ByVal stampText As String)
	Dim pdfDoc As New PdfDocument(New PdfReader(inputPdfPath), New PdfWriter(outputPdfPath))

	Dim doc As New Document(pdfDoc)

	' Add stamp (text) to each page
	Dim numPages As Integer = pdfDoc.GetNumberOfPages()
	For i As Integer = 1 To numPages
		doc.ShowTextAligned(New Paragraph(stampText), 36, 36, i, iText.Layout.Properties.TextAlignment.LEFT, iText.Layout.Properties.VerticalAlignment.TOP, 0)
	Next i

	doc.Close()
End Sub
$vbLabelText   $csharpLabel

IronPDF的圖像和文字印記方法簡單而靈活,允許將品牌內容或標籤輕鬆新增到PDF頁面上。 API使用熟悉的HTML/CSS樣式元素以便於自訂。 對於複雜的印記需求,IronPDF支持多個印記的高效執行Google字體整合網頁字體。 該庫還支持直接在PDF上繪製文字和位圖,並支持條碼印記以進行庫存跟踪。 對於精確控制,請探索翻譯PDF物件縮放PDF物件的功能。 iTextPdf也提供圖像和文字印記功能,但是設置需要更多手動配置以及對PDF佈局結構的了解。 能夠直接在PDF頁面上操作內容提供了可靠的印記工具,雖然iTextPdf的設置需要更多努力。

兩個庫能否將DOCX轉換為PDF?

在某些專案中,將DOCX文件轉換為PDF格式是必需的。 以下是IronPDF和iTextPdf如何處理此任務的比較,突出了它們的不同之處。 IronPDF提供原生的DOCX到PDF轉換,其他支持的格式包括RTF文件

IronPDF

using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");

// Advanced rendering with options
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;

// Handle mail merge
var mergeFields = new Dictionary<string, string>
{
    ["Name"] = "John Doe",
    ["Date"] = DateTime.Now.ToShortDateString()
};
PdfDocument mergedPdf = renderer.RenderDocxAsPdf("template.docx", mergeFields);

// 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");

// Advanced rendering with options
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;

// Handle mail merge
var mergeFields = new Dictionary<string, string>
{
    ["Name"] = "John Doe",
    ["Date"] = DateTime.Now.ToShortDateString()
};
PdfDocument mergedPdf = renderer.RenderDocxAsPdf("template.docx", mergeFields);

// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
Imports IronPdf

' Instantiate Renderer
Dim renderer As New DocxToPdfRenderer()

' Render from DOCX file
Dim pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")

' Advanced rendering with options
renderer.RenderingOptions.MarginTop = 50
renderer.RenderingOptions.MarginBottom = 50

' Handle mail merge
Dim mergeFields As New Dictionary(Of String, String) From {
    {"Name", "John Doe"},
    {"Date", DateTime.Now.ToShortDateString()}
}
Dim mergedPdf As PdfDocument = renderer.RenderDocxAsPdf("template.docx", mergeFields)

' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")
$vbLabelText   $csharpLabel

iTextPdf

與IronPDF不同,iTextPdf不內建支持將DOCX轉換為PDF。 要進行這種轉換,開發人員必須依靠第三方庫如DocX或Aspose.Words先將DOCX文件轉換為PDF相容的格式,再使用iTextPdf處理或修改。

IronPDF提供了直接的DOCX到PDF轉換內建解決方案,不需要額外的庫。 這使得它非常適合需要快速、整合轉換的開發者。 IronPDF還支持RTF轉PDF轉換以處理傳統文件格式,Markdown轉PDF以支援文件工作流程,XML轉PDF以處理結構化資料,以及圖片轉PDF轉換包括多幀TIFF支持。 為了改進文件處理,請探索郵件合併功能目錄生成。 相反,iTextPdf依賴外部庫進行DOCX轉換,需要額外的設置和依賴性,增加了項目的複雜性。

IronPDF和iTextPdf對於Bootstrap和現代CSS的支持度如何?

從Bootstrap風格的Web應用程式生成PDF時,完整的框架支持確保設計一致性,無需並行CSS文件或佈局修改。 了解HTML到PDF頁面分裂響應式設計考量對於專業輸出至關重要。 為了改善成果,使用CSS媒體型別自定義渲染延遲

IronPDF是否支持現代CSS框架?

IronPDF 的 Chromium 引擎完全支援以下內容:

  • Bootstrap 5: 完整的flexbox佈局、CSS網格、實用類別、所有元件
  • Bootstrap 4: 完整的卡片系統、導航、flex實用工具、響應式設計
  • Tailwind CSS:所有實用工具類別與瀏覽器準確渲染
  • Foundation: 完整的網格系統和組件庫
  • 現代CSS3:Flexbox、CSS Grid、自訂屬性、動畫、過渡

現實檢驗:IronPDF使用其響應式CSS功能以像素完美的準確度渲染Bootstrap主頁和所有官方範例。 該庫還支持自訂紙張尺寸視口控制以改善佈局渲染。 對於複雜佈局,使用渲染選項頁面方向設置。 該庫能夠處理國際語言和UTF-8支持全球應用。

iTextPdf的CSS限制是什麼?

iTextPDF使用pdfHTML,支持選擇性的CSS3:

  • 有限的flexbox支持: 在版本7.1.15加入但不完整
  • 沒有CSS網格: 不支持基於網格的Bootstrap佈局
  • Bootstrap 3限制: 現代Bootstrap 4/5組件需要解決方案
  • 手動佈局轉換:複雜佈局往往需要PDF特定程式碼

iTextPdf的文件明確指出,高級CSS功能可能無法按照預期渲染,要求開發者測試每個Bootstrap組件並經常建立簡化佈局。

對開發的影響: 團隊必須維護單獨的佈局程式碼以進行PDF生成,或需要大量的測試和修改Bootstrap組件,增加開發時間並減少設計一致性。

有關完整Bootstrap框架指導和CSS3渲染能力,請參閱Bootstrap & Flexbox CSS指南。 其他資源包括像素完美的格式化提示字體管理字距溶液以保持一致的字體排印。 對於Web應用程式,探索ASPX轉PDF轉換Angular.js PDF生成功能。

IronPDF和iTextPdf的程式範例告訴了我們什麼?

IronPDF和iTextPDF庫之間的功能比較表顯示了PDF操作的功能,包括HTML轉換、加密、隱藏、簽名、浮水印、印章和DOCX支持。

有關更詳細的範例,請存取IronPDF範例或探索程式碼範例庫演示部分提供了IronPDF功能的互動式範例。 其他資源包括並行PDF生成多執行緒處理異步範例,以支持高效能的應用程式。

IronPDF和iTextPdf在定價和授權方面如何比較?

IronPDF的定價選項是什麼?

IronPDF提供不同層次和額外功能用於購買授權。 開發者也可以購買Iron Suite,這將使他們用兩個產品的價格來存取所有Iron Software產品。 如果您還未準備好購買授權,IronPDF提供一個免費試用以進行完整功能評估。 授權頁面提供有關可用選項的完整詳情。 對於企業部署,探索授權金鑰管理程式設置授權金鑰

  • 永久授權:提供一系列永久授權,具體取決於您的團隊規模、專案需求和地點數量。 每種授權型別都附有電子郵件支援。
  • Lite License: 這個授權花費$999,支持一名開發人員、一個地點和一個專案。
  • Plus License: 支持三名開發人員、三個地點和三個專案,是lite授權的下一步升級,花費$1,499。 Plus授權除了基本的電子郵件支援外,還提供聊天支援和電話支援。
  • Professional License: 這個授權適合更大的團隊,支持十名開發人員、十個地點和十個專案,花費$2,999。 它提供與上一層級相同的聯絡支援渠道,但也提供螢幕共享支援。
  • 免版稅再分發: IronPDF的授權還提供免版稅再分發範围,額外費用為$2,999。
  • 不間斷的產品支持: IronPDF提供持續的產品更新、安保功能升級以及從其工程團隊獲得支持,費用為$999/年,或者一次性購買$1,999以獲得5年保障。
  • Iron Suite: 用$2,998,您將獲得所有Iron Software產品的存取,包括IronPDF、IronOCR、IronWord、IronXL、IronBarcode、IronQR、IronZIP、IronPrint和IronWebScraper。

IronPDF pricing comparison showing three perpetual license tiers (Lite, Plus, Professional) ranging from $999-$2,999, with a bundle promotion for Iron Suite offering 9 products for the price of 2

iTextPdf如何處理授權?

  • AGPL授權: iTextPDF核心庫是開源的,遵循AGPL授權條款,可按條件免費使用。 開發者必須釋出任何修改後的版本同樣遵循該授權。
  • 商業授權: 對於不符合AGPL條件的開發者,iTextPDF通過基於報價的模式提供商業授權。

關於授權升級和轉移,請存取IronPDF授權升級。 授權金鑰應用指南幫助實施,而授權金鑰配置提供部署選項。 關於授權問題的疑難排解,請參閱無法連接到授權伺服器授權擴展

IronPDF 和 iTextPdf 提供哪些檔案和支援?

  • 全面文件:提供所有功能的詳盡且使用者友好的文件。
  • 24/5支持:提供活躍的工程師支援。
  • 影片教程:提供循序漸進的YouTube影片指南。
  • 社區論壇:活躍的社區以提供額外支持。
  • 定期更新:每月產品更新以確保最新功能和安全補丁。

  • 完整文件:涵蓋所有功能的詳盡、使用者友好的文件
  • 24/5 支援:提供積極的工程支援
  • 影片教程:在 YouTube 上的分步影片指南
  • 社群論壇:透過 Stack Overflow 和 GitHub 提供的額外支援的活躍社群
  • 定期更新:每月產品更新,以確保最新功能和安全補丁
  • 程式碼範例:具有實際應用的詳盡程式碼範例庫
  • 故障排除指南:快速故障排除和平臺特定問題的詳細指南

IronPDF 提供關於常見問題的詳細故障排除指南,如 AWS 部署Azure 配置記憶體管理Docker 整合IIS 設置性能優化。 平臺特定指南涵蓋Windows 部署Linux 配置macOS 支援。 其他資源包括工程請求指導Azure 日誌管理AWS 日誌文件安全 CVE 資訊

  • 檔案:iText PDF 的檔案全面介紹了可用功能。
  • 範例和教程:程式碼範例和教程幫助開發者入門。
  • GitHub 社群:開發者可以報告問題、提交 pull 請求,並與 iTextPDF 團隊互動。
  • 定期更新:iTextPDF 提供頻繁的更新和改進。

有關 IronPDF 文件和支援的更多詳細資訊,請存取IronPDF 文件Iron Software YouTube 頻道。 探索針對特定功能的說明指南、詳細實施的API 參考和完整學習的教程VB.NET PDF 教程F# PDF 程式庫指南提供特定語言資源。 對於現代應用框架,探索Blazor 教程MAUI PDF 查看XAML 到 PDF 轉換。## 哪個 PDF 圖書館應該由高級 .NET 開發人員選擇?

在 .NET 的 PDF 操作工具領域中,IronPDF 和 iTextPdf 都為開發者提供有價值的解決方案。 IronPDF 因其在 .NET 平台上簡單的整合和像 DOCX 到 PDF 轉換這樣的使用者友好功能而著稱,並且不需要外部依賴。 對於高級渲染需求,IronPDF 支援JavaScript 執行WebGL 支援自定義渲染延遲以支持動態內容。 此程式庫還包括JavaScript 消息監聽器自定義 JavaScript 執行來製作互動式 PDF。 為了處理複雜的渲染場景,探索網路閒置等待渲染延遲配置初始渲染優化。 相反,iTextPdf 因其多功能性和豐富的功能而知名,對於組合其他工具時尤其有效,儘管它需要額外的依賴進行 DOCX 轉換。

為了提高性能,IronPDF 提供異步處理並行生成多執行緒支援以有效處理大批量 PDF 操作。 此程式庫還提供了高級功能,如PDF 壓縮快速網路查看的線性化PDF/A 合規性以滿足存檔要求。 其他企業功能包括支持電子發票的ZUGFeRD 支援的 PDF/A-3PDF/UA 合規性以提高可存取性以及PDF 版本控制。 對於雲端部署,IronPDF 提供遠程引擎選項Docker 容器支援本地與遠程引擎比較

最終,選擇 IronPDF 還是 iTextPdf 取決於項目的具體需求、授權偏好和所需的支援水平。 這兩個程式庫都提供可靠的方法來簡化 .NET 應用程式中的 PDF 工作流程。 對於優先考慮現代網路標準和易用性的開發者來說,IronPDF 的基於 Chrome 的渲染和完整 API 使其成為極佳的選擇。此程式庫的建立 PDF轉換 PDF組織 PDF的教程提供了全面的指導。 對於專業的文件處理,探索PDF 報告生成閱讀 PDF 文字PDF 到 HTML 轉換。 其他功能包括紙張列印網路列印機支援光柵化為圖片Base64 轉換。 需要 AGPL 授權或廣泛的低級 PDF 操作的人可能會發現 iTextPdf 更合適。

欲了解更多關於其他PDF圖書館的比較,探索Aspose vs IronPDFApryse vs IronPDFQuestPDF vs IronPDFSyncfusion vs IronPDF ,以便為您的 PDF 開發需求做出明智的決定。 有關部署指導,請查看IronPDF 安裝程式選項軟體安裝程式整合最佳部署實踐。 此程式庫的里程碑突顯了持續改進,包括Chrome 渲染增強相容性更新PDFium DOM 更新穩定性改進

請注意iTextPdf 是其相關所有者的註冊商標。 此網站與 iTextPdf 沒有關聯,不受其支持或贊助。 所有產品名稱、徽標和品牌均為其各自所有者的財產。 比較僅供資訊參考,並反映了撰寫時的公開可用資訊。

常見問題

如何在C#中將HTML轉換為PDF?

您可以使用IronPDF的RenderHtmlAsPdf方法將HTML字串轉換成PDF。也可以使用RenderHtmlFileAsPdf將HTML文件轉換為PDF。

IronPDF提供了哪些用於PDF建立和操作的功能?

IronPDF提供的功能包括HTML轉PDF,PDF合併,加密,數位簽名,加水印,以及DOCX轉PDF。

IronPDF如何簡化PDF簽名?

IronPDF允許您使用X509證書將數位簽名應用到PDF文件,提供安全您文件的簡單方法。

IronPDF可以在不同的操作系統上使用嗎?

是的,IronPDF支持跨平台相容性。它可無縫運行於Windows、Linux和Mac,並與.NET Core、.NET Standard和.NET Framework相容。

iTextPDF在文件加密方面與IronPDF有何不同?

雖然iTextPDF提供了詳細的加密標準設置,IronPDF通過內建的簡單加密方法簡化了該過程。

IronPDF使用者可以獲得哪些支持資源?

IronPDF提供了廣泛的支持,通過全面的文件,影片教程,社區論壇和24/5工程師支持。

IronPDF如何處理DOCX到PDF的轉換?

IronPDF包括原生的DOCX到PDF轉換功能,可無縫整合,不需要額外的程式庫。

IronPDF 提供哪些授權選項?

IronPDF提供永久授權,具有不同的層級,如Lite、Plus和Professional,以及免版稅再分發和持續的產品支持選項。

如何使用IronPDF將水印應用於PDF?

IronPDF允許您使用HTML和CSS輕鬆地應用水印,使您能快速新增文字或圖像水印並根據需要自定義它們。

什麼使IronPDF對於開發.NET應用程式的開發者來說合適?

IronPDF設計為使用者友好的簡化API,使得它在HTML轉PDF、加密、數位簽名等任務中高效,非常適合.NET開發者。

Curtis Chau
技術作家

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

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

iText Logo

厭倦了昂貴的續費和過時的產品更新?

iText輕鬆切換,透過我們的工程遷移支援和更好的交易。

IronPDF Logo

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話