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

IronPDF與iText7的比較

一個體面且簡單的PDF操作工具可以簡化許多涉及創建和編輯PDF文檔的任務和流程。 在.NET生態系統中,有兩個流行的庫——IronPDF和iText——允許生成PDF而不依賴任何Adobe。 它們都提供多種功能,例如創建、編輯、轉換等,但本文將重點比較這些庫在三個標準下的表現:它們提供的功能、文檔質量,以及這些公司針對產品使用所採取的定價政策。

IronPDF和iText概覽

IronPDF是一個著名的.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框架中處理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 的應用環境中工作。

  • IDEs: 與 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提供了一個簡明且便捷的工具。 IronPDF使用ChromePdfRenderer將HTML內容轉換為PDF,使用戶能夠獲得像素完美的PDF文檔。 用戶可以直接從HTML字符串創建PDF,也可以包含外部資產如圖像和可選基路徑,如高級示例所示。 另一方面,iText使用其HtmlConverter類從HTML文件創建PDF文檔,採用了一種基本方法。

加密 PDF 文件

使用IronPDF加密和解密PDF文件在許多工作場所是至關重要的。 下面,我們將看到iText和IronPDF是如何處理PDF加密的。

IronPDF

using IronPdf;
using System;

// Open an Encrypted File, alternatively create a new PDF from HTML
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;

// Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
using IronPdf;
using System;

// Open an Encrypted File, alternatively create a new PDF from HTML
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;

// Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
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中的文本部分。下面的代碼示例將演示如何使用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並未提供一個內建的刪減工具,而是使用上面顯示的方法覆蓋用戶希望刪減的內容。 這可能導致潛在問題,因為這些矩形實際上並未移除或正確刪減文本,其他人可能會複製和粘貼被刪減的數據。 ### 簽署PDF文件

能夠使用IronPDF數字簽署PDF文檔能夠節省時間,特別是將此設為自動化過程時。

以下是一些代碼段,比較IronPDF與iText在文檔數字簽名方面的區別。 在對PDF文件數字簽名時,IronPDF提供了一個簡明且強大的工具完成此過程。

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

其簡單性允許過程快速完成,為任何需要此功能的開發者節省時間。 iText需要一個更長且更復雜的過程來對PDF文件進行數字簽名。 雖然他們有能力使用不同的界面選項和密鑰為用戶提供更多的控制權,但這個工具如何執行這項工作的複雜性可能會阻礙其使用。 ### 將水印應用於PDF文件

能夠在PDF上添加和個性化水印會极大地帮助机密信息、版权保护、品牌推广或任何涉及敏感信息的任务。

以下是IronPDF和iText將水印應用於PDF文件的比較。 IronPDF的易用且直觀的API允許用戶快速地為其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

其使用HTML/CSS進一步簡化了過程,無損於任何定制控制。 iText的應用於PDF添加水印方法需要更多手工操作,可能會拖慢過程。 ### 在PDF上加印圖像和文字

有時PDF頁面需要在PDF上加印文字或圖片,類似於需要將水印應用於它們的PDF文件。

我們現在將比較IronPDF和iText在PDF文檔上添加內容的表現。 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,
};

// 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

其API易於理解和使用,尤其適合了解HTML/CSS的開發者。 iText使用其圖片和文本標記工具為用戶提供對其PDF文件中顯示內容的更多控制,儘管過程可能更偏重手工操作。 ### 將DOCX轉換為PDF

有時,你可能需要將PDF從一種格式轉換到另一種格式。

在此情況下,我們正在研究使用IronPDF進行DOCX到PDF的轉換以及IronPDF和iText處理此過程的不同方式。 iText本身無法處理DOCX到PDF的轉換;

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

它依賴於外部庫,如DocX或Aspose.Words。 IronPDF為開發者提供了一個簡單明了的DOCX到PDF轉換工具,讓轉換DOCX文件到PDF格式變得容易,不需要外部庫。

iText,另一方面,依賴於外部庫來完成此過程。 iText C# HTML 到 PDF 替代品

代碼示例比較的摘要

要獲得更詳細的示例,請訪問IronPDF從HTML创建PDF的示例

在現實開發中常見的考慮因素是每個庫對于現代CSS框架的支持能力如何。

Bootstrap 和現代 CSS 框架支持

隨著Bootstrap、Tailwind CSS和Foundation構成了大多數當代應用程序的基礎,框架兼容性可能會極大地影響您的開發工作流程和輸出質量。 IronPDF的Chrome渲染引擎提供完整的,適用於生產的所有現代CSS框架支持:

IronPDF:完整現代框架支持

  • Bootstrap 5:所有佈局均具原生flexbox和CSS Grid支持

  • Tailwind CSS:完整的實用至上框架支持
  • Modern CSS3:變換、動畫、自定义属性和高级选择器
  • 框架验证:成功渲染Bootstrap模板
  • Framework validation: Successfully renders the Bootstrap homepage and Bootstrap templates

iText7:有限的框架支持

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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

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进行用户界面设计,并且需要与其网页设计相匹配的PDF导出,iText7需要要么对HTML/CSS进行显著重新设计以用于PDF生成,要么與外部瀏覽器自動化工具集成,這大幅增加了複雜性和開發時間。

欲了解详尽的CSS框架兼容性信息,请参阅Bootstrap和Flexbox CSS指南

定價和許可:IronPDF與iText庫

IronPDF許可選項提供多個級别和額外功能的許可購買選项。

IronPDF定價和許可

開發者還可以購買Iron Suite,以兩者的價格獲取Iron Software的所有產品。 如果你還沒有準備好購買許可,IronPDF提供一個為期30天的免費試用版。 - 永久許可:提供一系列永久許可,具體取決於你的團隊規模、項目需求和地點數量。

  • 輕量許可:該許可支援一名開發者、一個地點和一個項目。 每種授權類型都包含郵件支持。

  • 加強許可:支援三名開發者、三個地點及三個項目,成本為$1,199。

加強許可提供聊天、電話和電子郵件支持。 - 專業許可:適用於較大的團隊,支持十名開發者、十個地點和十個項目的成本為$2,399。

  • 不中断产品支持:以$1,199/年的价格或一次性購買$2,399,獲取持續的產品更新、安全功能升級和来自其工程團隊的支持以實現5年的覆盖。 除前一級別的聯絡支持頻道,同時提供屏幕共享支持。

  • 免版稅再分發: IronPDF 的許可證還提供免版稅再分發保障,額外費用為 $2,399。

  • 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文檔和支持的更多信息,請訪問Iron Software YouTube频道

For more details on IronPDF documentation and support, visit IronPDF Documentation and the Iron Software YouTube Channel.

結論

IronPDF以其在.NET Core、Framework和Standard等平台間的簡單集成而著称,並且擁有全面的功能,例如HTML到PDF轉換及多種高級安全選項。 另一方面,以Java血統著称的iText提供了在開源和商業許可下的強大PDF生成和操作工具,強調多功能性和定制性。 選擇取決於項目要求、許可偏好和需要的技術支持水平。

無論是選擇簡單且靈活的IronPDF,還是功能豊富的開源PDF庫iText,開發人員都有充足的資源在應用中高效簡化PDF工作流。

請注意iText 是其各自所有者的註冊商標。

您可以嘗試 30 天免費試用以檢視它們的可用功能。

本站与iText无关,不受其认可或赞助。 This site is not affiliated with, endorsed by, or sponsored by 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 機器人,結合科技與創意的樂趣。