跳過到頁腳內容
產品比較
IronPDF 與 iText7 的 HTML 到 PDF 比較

IronPDF與iText7的比較

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 文件所涉及的許多任務和流程。 在 .NET 的生態系統中,有兩個廣受歡迎的函式庫 - IronPDF 和 iText - 可以在不依賴任何 Adobe 的情況下產生 PDF。 它們都提供各種功能,例如建立、編輯、轉換等,但本文將集中比較這些函式庫,比較的標準有三:它們所提供的功能、它們所提供的文件品質,以及這些公司對於使用其產品所採取的價格政策。

IronPDF 和 iText 的概述

IronPDF for .NET 是一個著名的 .NET PDF 函式庫,可讓程式設計師輕易地建立、修改 PDF 文件並與之互動。 它可在不同的 .NET 環境中使用,包括 Core、8、7、6 和 Framework,因此具有高度彈性,可滿足各種開發需求。 IronPDF的主要功能是其豐富的功能集,例如 HTML 到 PDF 的轉換、合併 PDF 的能力、PDF 加密以及數位簽章的應用等等。 文件的撰寫方式要讓使用者可以毫無困難地理解,而資料庫本身則要有強大的技術支援。

iText 是最受歡迎的 PDF 函式庫之一,適用於 Java 以及 .NET (C#)。 iText Core 8 提供企業級的可編程解決方案,用於建立和處理 PDF 檔案。 iText 提供許多不同功能的支援,並依據開放原始碼 (AGPL) 授權和商業授權釋出。 這意味著,由於其通用性,它能夠涵蓋數位轉換專案中的各種使用案例。

跨平台相容性

IronPDF 和 iText 與各種平台相容; 他們可以在許多不同的系統和 .NET Framework 內處理 PDF。 以下我們將比較各產品所支援的架構和平台。

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 vs. 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");
Imports IronPdf

' Configure security settings
Installation.EnableWebSecurity = True

' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()

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

' Advanced Example with HTML Assets
' Load external HTML assets: images, CSS and JavaScript.
Dim 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);
    }
}
Imports iText.Html2pdf

Shared Sub Main(ByVal args() As String)
	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
$vbLabelText   $csharpLabel

將 HTML 轉換為 PDF 時,IronPDF。 提供了簡潔方便的工具來完成這項任務。 利用 ChromePdfRenderer 將 HTML 內容轉換成 PDF,IronPDF 能夠出色地為使用者提供像素完美的 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");
Imports IronPdf
Imports System

' Open an Encrypted File, alternatively create a new PDF from HTML
Private 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();
    }
}
Imports System
Imports System.IO
Imports System.Text
Imports iText.Kernel.Pdf

Public Class EncryptPdf
	Public Shared ReadOnly DEST As String = "results/sandbox/security/encrypt_pdf.pdf"
	Public Shared ReadOnly SRC As String = "../../../resources/pdfs/hello.pdf"

	Public Shared ReadOnly OWNER_PASSWORD As String = "World"
	Public Shared ReadOnly USER_PASSWORD As String = "Hello"

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

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

	Protected Sub ManipulatePdf(ByVal dest As String)
		Dim document As 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 Or EncryptionConstants.DO_NOT_ENCRYPT_METADATA)))
		document.Close()
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF。為使用者提供了一種直接加密 PDF 檔案的方式,同時也賦予使用者許多控制權,例如編輯元資料和調整安全設定,如將文件設定為唯讀或限制使用者的複製和貼上等動作。 另一方面,iText 採用較低階且較長的方法,在建立文件時應用 PDF 加密,並使用 AES-128 等加密標準指定所有者和使用者密碼,以及列印權限等權限。

重製 PDF 內容

在處理機密或私人資訊時,偶爾可能需要 使用 IronPDF 在 PDF 中刪除文字 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");
Imports IronPdf

Private pdf As PdfDocument = 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();
        }
    }
}
Imports System
Imports System.IO
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.Layout.Element
Imports iText.Layout.Properties
Imports iText.Kernel.Colors

Private src As String = "input.pdf"
Private dest As String = "output_redacted.pdf"

Using reader As New PdfReader(src)
Using writer As New PdfWriter(dest)
Using pdfDoc As New PdfDocument(reader, writer)
	' Iterate through each page
	Dim pageNum As Integer = 1
	Do While pageNum <= pdfDoc.GetNumberOfPages()
		Dim page As PdfPage = pdfDoc.GetPage(pageNum)
		Dim canvas As New PdfCanvas(page)
		Dim rectanglesToRedact() As Rectangle = { New Rectangle(100, 100, 200, 50) } ' Define rectangles to redact

		' Overlay black rectangles to simulate redaction
		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
End Using
End Using
$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");
Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates

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

' Create PdfSignature object
Private sig = New PdfSignature(cert)

' Sign PDF document
Private pdf As PdfDocument = 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}");
        }
    }
}
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。 提供了一個簡潔且功能強大的工具來完成此程序。 其簡易性可讓流程快速進行,為任何因簽名需求而實作的開發人員節省時間。 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");
Imports IronPdf

' Stamps a Watermark onto a new or existing PDF
Private renderer = New ChromePdfRenderer()

Private 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();
    }
}
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 可讓使用者快速在 PDF 檔案上套用自訂水印,並完全控制整個過程。 它對 HTML/CSS 的使用進一步簡化了流程,而不會失去任何客製化控制。 iText在 PDF 中加入水印的方法需要更多的手動工作,可能會拖慢流程。

在 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");
Imports IronPdf
Imports IronPdf.Editing

Private renderer As New ChromePdfRenderer()

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

' Create text stamper
Private textStamper As New TextStamper() With {
	.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
Dim imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.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();
}
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 的開發人員而言。 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");
Imports IronPdf

' Instantiate Renderer
Private renderer As New DocxToPdfRenderer()

' Render from DOCX file
Private pdf As PdfDocument = 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 的替代方案

如需更詳細的範例,請造訪 從 HTML 建立 PDF 的 IronPDF 範例

Bootstrap 與現代 CSS 架構支援。

在實際開發過程中經常出現的一個關鍵考慮因素是每個函式庫對現代 CSS 框架的處理能力。 由於 Bootstrap、Tailwind CSS 和 Foundation 是大多數當代網路應用程式的基礎,因此框架相容性會對您的開發工作流程和輸出品質產生重大影響。

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 class='mb-4'>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 class='mb-4'>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");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()

Dim bootstrapProgressBars As String = "
<!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 class='mb-4'>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>"

Dim 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 文件,建議開發人員: 1.避免使用複雜的 CSS 佈局,包括 flexbox 2.使用表格式佈局取代現代網格系統 3.將 Bootstrap 元件簡化為基本 HTML 4.由於框架相容性有限,因此必須徹底測試

實際影響:如果您的應用程式使用 Bootstrap 作為其使用者介面,並且您需要匯出與 Web 設計相符的 PDF,則 iText7 需要對 HTML/CSS 進行大量重新設計才能產生 PDF,或者需要與外部瀏覽器自動化工具集成,這將大大增加複雜性和開發時間。

如需全面的 CSS 框架相容性資訊,請參閱 Bootstrap & Flexbox CSS 指南

定價與授權:IronPDF vs. iText Library

IronPDF。 定價與授權

IronPDF授權選項提供購買授權的各種等級和附加功能。 開發人員也可以購買 Iron Suite,以購買兩套產品的價錢即可使用 Iron Software 的所有產品。 如果您尚未準備好購買授權,IronPDF 提供 免費試用版,試用期為 30 天。

  • 永久 License: 根據您的團隊規模、專案需求和地點數量,提供一系列永久 License。 每種授權類型都附有電子郵件支援。

  • Lite License: 此 Lite License 支援一位開發人員、一個地點和一個專案。

  • Plus 授權:支援三名開發人員、三個地點和三個項目,費用為 $1,499。 Plus License 提供聊天、電話和電子郵件支援。

-專業許可證:適用於更大的團隊,支援十名開發人員、十個地點和十個項目,適用於 $2,999。 它提供與前幾層相同的聯絡支援管道,但也提供螢幕分享支援。

-免版稅再分發: IronPDF 的許可還提供免版稅再分發保障,需額外支付 $2,999。

-不間斷的產品支援:每年可獲得 $1,499 的持續產品更新、安全功能升級以及工程團隊的支持,或一次性購買 $2,999 即可獲得 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 vs. 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 的簡單性和靈活性,或是 iText 這個開放原始碼 PDF 函式庫的廣泛功能集,開發人員都有充足的資源在其應用程式中有效地簡化 PDF 工作流程。

您可以嘗試30天免費試用,以查看其可用功能。

請注意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 機器人,結合科技與創意的樂趣。

iText Logo

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

iText 輕鬆轉換為我們的工程遷移支援和更優惠的價格。

IronPDF Logo

鋼鐵支援團隊

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