PRODUCT COMPARISONS

iTextSharp C# HTML to PDF Alternative for .NET Core

Published October 23, 2024
Share:

IronPDF and iText 7 (formerly known as iTextSharp) both provide the ability to generate, manipulate, and print PDFs in .NET and .NET Core.

Which C# PDF library is best suited for your .NET project? The goal of this article is to help readers make a proper and informed decision.

IronPDF is a prominent .NET PDF library that allows developers to easily create, modify, and interact with PDF documents. It supports various .NET environments, including .NET Core, .NET 8, 7, 6, and Framework, making it highly versatile. Key features of IronPDF include HTML to PDF conversion, merging PDFs, encryption, and digital signatures. The documentation is user-friendly, and technical support is robust.

iTextSharp is a powerful PDF library for the .NET platform, originally derived from iText (which is Java-based). It provides enterprise-level solutions for creating and manipulating PDFs and is available under both open-source (AGPL) and commercial licenses. The iTextSharp core library offers a high degree of flexibility, allowing developers to create PDFs from scratch, manage forms, apply digital signatures, add PDF functionality, and more.

Cross-Platform Compatibility

IronPDF is:

  • .NET First
  • Openly commercial with published pricing
  • Focuses on rendering PDFs from HTML so that developers do not need to learn how PDFs work
  • A great choice for pragmatic coders trying to get a job done.

iText (iTextSharp) is:

  • Java First
  • Very much Open Source. We may call them, for a quote for use other than in strict open source AGLP projects.
  • Focuses on rendering PDFs using a programmatic API based around how PDFs work internally
  • A great choice for free and academic projects

IronPDF supports a wide range of platforms and environments, ensuring seamless integration and deployment in various systems:

iTextSharp has been around for at least 6 years, based on an open-source Java codebase called iText, and still has somewhat of a Java flavor. Developers who first learned Java may find this library familiar.

IronPDF is a .NET-first library with an API designed around ease of use in Visual Studio. .NET has been in existence for almost 20 years, continually growing and expanding, and opening up many possibilities, which IronPDF is designed to leverage. It allows us to create and manipulate PDF documents in .NET framework projects. You can download IronPDF as an alternate PDF library for iTextSharp users.

  • .NET Core (8, 7, 6, 5, and 3.1+)

  • .NET Standard (2.0+)

  • .NET Framework (4.6.2+)
  • App environments: IronPDF works in app environments including Windows, Linux, Mac, Docker, Azure, and AWS

  • IDEs: Works with IDEs such as Microsoft Visual Studio and JetBrains Rider & ReSharper

  • OS and Processors: Supports several different OS & processors including Windows, Mac, Linux, x64, x86, ARM

iTextSharp:

  • .NET versions: Supports .NET Core (2.x, 3.x), .NET Framework (4.6.1+), .NET 5+.

  • App environments: Runs on Windows, macOS, Linux, and Docker.

  • Open Source: Available under AGPL license.

Key Feature Comparison: IronPDF vs. iTextSharp

IronPDF and iTextSharp both offer a range of features and tools that can be used to work with PDF files; the focus of this next section will be to take a closer loo k at some of these features and how the two libraries compare when it comes to carrying out different PDF-related tasks.

IronPDF

  • HTML to PDF Conversion: Supports HTML, CSS, JavaScript, and images.

  • PDF File Manipulation: Split and then merge documents, change the formatting of and edit existing PDF documents

  • Security: PDF encryption and decryption.

  • Editing: Add annotations, bookmarks, and outlines.

  • Templates: Apply headers, footers, and page numbers.

  • Watermarking: Easily apply text and image watermarks to PDF files; take advantage of its use of HTML/CSS to gain full control over the process.

  • PDF Stamping: Stamp images and text onto your PDF documents using IronPDF.

For more information on the extensive set of features IronPDF has to offer, visit the IronPDF features page.

iTextSharp:

  • PDF Creation: Supports creating PDF documents from scratch.

  • Forms: Create and edit PDF forms.

  • Digital Signatures: Sign PDF documents.

  • Compression: Optimize PDF file sizes.

  • Content Extraction: Extract text and images from PDFs.

  • Open Source: Available under AGPL license.

  • Customizability: High level of customization for advanced use cases.

Comparison of PDF Functionality Features Between IronPDF and iTextSharp

HTML to PDF Conversion

Converting HTML content into PDF is a very simple task that is done in many different offices and workspaces. Below are the code examples comparing how IronPDF and iText approach this process.

IronPDF

using IronPdf;

// Disable local disk access or cross-origin requests
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.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
using IronPdf;

// Disable local disk access or cross-origin requests
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.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Imports IronPdf

' Disable local disk access or cross-origin requests
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.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")
VB   C#

iTextSharp

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
VB   C#

When converting HTML to PDF, IronPDF offers a concise and convenient tool for carrying out this task. Utilizing the ChromePdfRenderer to convert HTML content into PDFs, IronPDF excels in providing users with pixel-perfect PDF documents. Users can create PDFs directly from HTML strings, as shown in the first example, or include external assets like images with an optional base path, as demonstrated in the advanced example. iTextSharp, on the other hand, uses HtmlConverter to convert HTML files, but the process requires more setup.

Encrypting PDF Files

Encryption and decryption of PDF documents are vital at many workplaces. To handle this task easily it's necessary to have a tool that can do it conveniently. In the code below, we will see how iTextSharp and IronPDF tackle the encryption of PDFs.

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
// The following code makes a PDF read only and will disallow copy & paste and printing
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
// The following code makes a PDF read only and will disallow copy & paste and printing
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
' The following code makes a PDF read only and will disallow copy & paste and printing
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")
VB   C#

iTextSharp

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
VB   C#

IronPDF offers users a straightforward way to encrypt PDF files while also giving users plenty of control of the process, including editing metadata and adjusting security settings such as making documents read-only or restricting user actions like copy and paste. On the other hand, iTextSharp provides more granular control but requires additional configuration, such as specifying encryption standards and permissions.

Redact PDF Content

Occasionally, while handling confidential or private information, it may be necessary to redact portions of a PDF file. The following examples demonstrate how you can redact text using IronPDF in comparison with iTextSharp.

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")
VB   C#

iTextSharp

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) }; // Example: 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) }; // Example: 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) } ' Example: 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
VB   C#

IronPDF's redaction tool is concise and easy to use, needing only a few lines of code to streamline the redaction process. This helps raise efficiency around PDF redaction tasks and gives users an easy way to keep their sensitive and private data safe.

On the other hand, iTextSharp lacks a built-in redaction feature, requiring you to manually draw black rectangles over the content you wish to redact. However, this approach can leave the text under the rectangle accessible, allowing users to copy-paste the hidden data, so it doesn’t provide true redaction.

Signing PDF documents

Being able to sign digital documents such as PDF files and then making it an automated process could be time saving. The following code snippets compare how IronPDF and iTextSharp handle digital signatures.

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")
VB   C#

iTextSharp

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
VB   C#

When applying signatures to PDF files digitally, IronPDF presents a condense yet powerful tool for completing this process. Its simplicity allows for the process to be conducted quickly, saving time for any developer who implements it for their signing needs. In contrast, iTextSharp requires more setup and involves additional steps to handle digital signatures, making it more complex, though potentially more flexible for advanced users.

Applying Watermarks to PDF documents

The ability to add and personalize watermarks on PDFs through software can greatly assist with confidentiality, copyright protection, branding or any other tasks involving sensitive information. The following is a comparison of how IronPDF and iTextSharp apply watermarks to PDF files.

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")
VB   C#

iTextSharp

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();

            // Creating a dictionary that maps resource names to graphics state parameter dictionaries
            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();

            // Creating a dictionary that maps resource names to graphics state parameter dictionaries
            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()

			' Creating a dictionary that maps resource names to graphics state parameter dictionaries
			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
VB   C#

IronPDF's easy and intuitive API lets users apply custom watermarks to their PDF files quickly, while giving them full control over the process. Its use of HTML/CSS further simplifies the process without losing any control over the customization. iTextSharp's approach to adding watermarks to PDFs requires more manual work to carry out the task, which can slow the process down.

Stamping Images and Text onto a PDF

There are moments when PDF pages need to be stamped with content, similar to how one might need to apply watermarks to their PDF files. Let's see how IronPDF compares with iTextSharp:

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")
VB   C#

iTextSharp

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

    var document = new Document(pdfDoc);
    ...
}
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));

    var document = new Document(pdfDoc);
    ...
}
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 document As New Document(pdfDoc)
	'...
End Sub
VB   C#

By quickly glancing at the code, you can see that IronPDF is pragmatic, based on common end-user requirements.

iText is a lower-level library that focuses on a drawing API where we add objects, shapes, and text to pages.

iTextSharp.dll uses a primarily programmatic model to render PDFs. When using the iTextSharp PDF library, each piece of PDF text, graphic, table, or line is “plotted” or drawn onto a PDF. The API appears low-level and is focused on the PDF document standard. This model allows precision but may require developers to learn a little about how PDFs work. Closely matching an existing design style or web assets may take some iteration and reading the iTextSharp documentation. In keeping with its heritage, the methodology and programmatic interface have a distinct Java flavor.

In contrast, IronPDF uses a full embedded web browser renderer to convert HTML to PDF. Following short (1- and 2-line) C# code examples for HTML to PDF conversion, developers can generate PDFs from existing or new HTML, images, and CSS. This allows developers to work closely with existing web assets and also work in parallel with designers during a project. iText does include HTML to PDF functionality for C# .NET, though it is not, apparently, the library's dominant feature.

Read on for more comparative details on the different ways that IronPDF and iTextSharp can help developers achieve the following goals:

1. Licensing

Licensing options are also an important factor in developer projects. iTextSharp is Open Source under the AGPL license agreement. When licensed under AGLP, anyone who uses any part of an application that contains iTextSharp (even across a company network or the internet) may be entitled to a full copy of the app's full source code. This is excellent for academic work. If we wish to use iTextSharp in commercial applications it is best practice to contact iText and ask them for a quote on the pricing for iText commercial usage.

IronPDF is free for development, and can then be licensed for commercial deployment at publicly published, reasonable prices starting at $749.

IronPDF and iTextSharp

This is how the two libraries stack up:

IronPDFiTextSharp
Convert HTML to PDF via a full built-in web browserBasic HTML to PDF via a pdfHTML add-on
Rendering focus: Embedded web browserRendering focus: Programmatic drawing model
IronPDF has explicit licenses with published pricesAGPL! Commercial use pricing not published.
Easy to Code with .NET First DesignBased on a Java API
Not suited to academic assignments and coursework Excellent for academic assignments and research

Key Differences

Generate PDF from HTML using IronPDF

IronPDF enables .NET and .NET Core developers to generate, merge, split, edit, and extract PDF content easily in C#, F#, and VB.NET for .NET Core and .NET Framework, as well as create PDFs from HTML, ASPX, CSS, JS, and image files.

It makes use of a fully embedded web browser to convert HTML to PDF. This allows developers to generate PDFs from HTML, images, and CSS, and to work closely with existing web assets and also work in parallel with designers during a project.

2. IronPDF Features

IronPDF really focuses on developer productivity. The library simplifies many common complex PDF code tasks into convenient C# methods to extract text and images, sign PDFs, edit PDFs with new HTML, and more, without the developer needing to study the PDF document standard to understand how to achieve their best result.

  • Generating PDF documents from HTML, images, and ASPX files
  • Reading PDF text
  • Extracting data and images from PDFs
  • Merging PDF documents
  • Splitting PDFs
  • Manipulating PDFs

2. iTextSharp Documentation Features

The iTextSharp.dll uses a primarily programmatic model to render PDFs, and it has advanced PDF manipulation APIs that are powerful and follow the PDF standard closely.

  • AGLP strict open source licensing
  • Programmatic drawing model
  • Edit and Read PDFs
  • Solid functionality for PDF manipulation
  • Based on a Java library

Let's compare by creating an example project utilizing both libraries:


Example Project

Create an ASP.NET Project

Make use of the following steps to create an ASP.NET website:

  1. Open Visual Studio
  2. Click File > New Project
  3. Select Web under Visual C# in the Project type listbox
  4. Select ASP.NET Web Application
New Project related to Create an ASP.NET Project

Figure 1New Project

  • Click OK
  • On the next screen, select Web Forms as shown in Figure 2 underneath
Web Form related to Create an ASP.NET Project

Figure 2Web Forms

  • Click OK

Now we have something to work with. Let’s Install IronPDF.


Get Started

3. IronPDF Library Installation

In order to make use of IronPDF, you first need to install it (free). There are two options:

  • NuGet
  • Download the library

Let’s have a closer look.

3.1. Install using NuGet

There are three ways to install the IronPDF NuGet package:

  1. Visual Studio
  2. Developer Command Prompt
  3. Download the NuGet Package directly

Let’s do them one-by-one.

3.2. Visual Studio

Visual Studio provides the NuGet Package Manager for you to install NuGet packages in your projects. You can access it via the Project Menu, or by right-clicking your project in the Solution Explorer. Both these options are shown below in Figures 3 and 4

Project Menu related to 3.2. Visual Studio

Figure 3Project menu

Solution Explorer related to 3.2. Visual Studio

Figure 4Right-click Solution Explorer

After you have clicked Manage NuGet Packages from either option, Browse for the IronPDF package and install it as shown in Figure 5.

Install Ironpdf Nuget Package related to 3.2. Visual Studio

Figure 5Install IronPDF NuGet Package

3.3. Developer Command Prompt

The following steps open the Developer Command Prompt and installs the IronPDF NuGet package

  1. Search for your Developer Command Prompt – it is usually under your Visual Studio folder
  2. Type in the following command: PM > Install-Package IronPdf
  3. Press Enter
  4. The package will be installed
  5. Reload your Visual Studio project

3.4. Download the NuGet Package directly

In order to download the NuGet package:

  1. Navigate to https://www.nuget.org/packages/IronPdf/
  2. Click on Download Package
  3. After the package has downloaded, double click it
  4. Reload your Visual Studio project

3.5. Download the .DLL Library

The second way to install IronPDF is by direct download.

Download Ironpdf Library related to 3.5. Download the .DLL Library

Figure 6Download IronPDF library

Reference the Library in your project by using the next steps:

  1. Right-click the Solution in the Solution Explorer
  2. Select References
  3. Browse for the IronPDF.dll library
  4. Click OK

Now that you’re set up, we can start playing with the awesome features in the IronPDF library after the setup for iTextSharp.

Install iTextSharp by using NuGet

There are three ways to install the iTextSharp NuGet package, they are:

  • Visual Studio
  • Developer Command Prompt
  • Download the NuGet Package directly

Let’s do them one-by-one.

For Visual Studio, search for iText and install the relevant packages, as shown next.

Itext related to Install iTextSharp by using NuGet

Figure 7iText

Or, in the Developer Command Prompt (as shown previously, enter the following command)

  • PM > Install-Package itext7

Or, download iText 7 directly from their website.

Now that you have created the necessary projects, let’s compare these two libraries in code.


Compare the Code

4. Create a PDF from an Existing URL

The following code downloads a webpage and converts it to a PDF document.

4.1. IronPDF Website to PDF

The following code uses IronPDF to create a PDF document directly from a website address. Custom Headers and Footers are also included.

/**
IronPDF URL to PDF
anchor-ironpdf-website-to-pdf
**/
private void ExistingWebURL()
{
    // Create a PDF from any existing web page
    var Renderer = new IronPdf.ChromePdfRenderer();

    // Create a PDF from an existing HTML
    Renderer.RenderingOptions.MarginTop = 50;  //millimetres
    Renderer.RenderingOptions.MarginBottom = 50;
    Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
    Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
    {
        CenterText = "{pdf-title}",
        DrawDividerLine = true,
        FontSize = 16
    };
    Renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
    {
        LeftText = "{date} {time}",
        RightText = "Page {page} of {total-pages}",
        DrawDividerLine = true,
        FontSize = 14
    };

    Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

    Renderer.RenderingOptions.EnableJavaScript = true;
    Renderer.RenderingOptions.RenderDelay = 500; //milliseconds

    using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");

    PDF.SaveAs("wikipedia.pdf");
}
/**
IronPDF URL to PDF
anchor-ironpdf-website-to-pdf
**/
private void ExistingWebURL()
{
    // Create a PDF from any existing web page
    var Renderer = new IronPdf.ChromePdfRenderer();

    // Create a PDF from an existing HTML
    Renderer.RenderingOptions.MarginTop = 50;  //millimetres
    Renderer.RenderingOptions.MarginBottom = 50;
    Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
    Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
    {
        CenterText = "{pdf-title}",
        DrawDividerLine = true,
        FontSize = 16
    };
    Renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
    {
        LeftText = "{date} {time}",
        RightText = "Page {page} of {total-pages}",
        DrawDividerLine = true,
        FontSize = 14
    };

    Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

    Renderer.RenderingOptions.EnableJavaScript = true;
    Renderer.RenderingOptions.RenderDelay = 500; //milliseconds

    using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");

    PDF.SaveAs("wikipedia.pdf");
}
'''
'''IronPDF URL to PDF
'''anchor-ironpdf-website-to-pdf
'''*
Private Sub ExistingWebURL()
	' Create a PDF from any existing web page
	Dim Renderer = New IronPdf.ChromePdfRenderer()

	' Create a PDF from an existing HTML
	Renderer.RenderingOptions.MarginTop = 50 'millimetres
	Renderer.RenderingOptions.MarginBottom = 50
	Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
	Renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
		.CenterText = "{pdf-title}",
		.DrawDividerLine = True,
		.FontSize = 16
	}
	Renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
		.LeftText = "{date} {time}",
		.RightText = "Page {page} of {total-pages}",
		.DrawDividerLine = True,
		.FontSize = 14
	}

	Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print

	Renderer.RenderingOptions.EnableJavaScript = True
	Renderer.RenderingOptions.RenderDelay = 500 'milliseconds

	Dim PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format")

	PDF.SaveAs("wikipedia.pdf")
End Sub
VB   C#

IronPDF can help you add text or images onto PDFs in a way that’s really versatile and customizable; it lets you take complete charge. It is easy to understand and work with the API, especially for developers familiar with HTML/CSS. iTextSharp makes use of its image and text stamping tools to give users more control over the content displayed on their PDF files, although the process can end up being more manual.

Convert DOCX to PDF

Sometimes, you might have to convert PDFs from one format to the other. In this case, we looking at DOCX to PDF conversion and comparing how IronPDF and iTextSharp handle this process differently.

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")
VB   C#

iTextSharp

Unfortunately, iTextSharp does not provide built-in DOCX to PDF conversion functionality, and developers must rely on external libraries like Aspose.Words for this task.

IronPDF provides developers with a straightforward and concise tool for handling DOCX to PDF conversion tasks, making it easy to convert DOCX files to a PDF format with the need for external libraries. iTextSharp, on the other hand, relies on external libraries in order to carry out this task.

Summary of the Code Examples Comparison

Itextsharp 1 related to Summary of the Code Examples Comparison

For more detailed examples, visit IronPDF Examples.

Pricing and Licensing: IronPDF vs. iTextSharp Library

IronPDF Pricing and Licensing

IronPDFhas different levels and additional features for purchasing a license. Developers can also buy Iron Suite which, gives you access to all of Iron Software’s products at the price of two. If you’re not ready to buy a license, IronPDF provides a free trial that lasts 30 days.

  • Perpetual licenses: Offers a range of perpetual licenses depending on the size of your team, your project needs, and the number of locations. Each license type comes with email support.

  • Lite License: This license costs $749 and supports one developer, one location, and one project.

With this code segment, we have transformed the Tiger Wikipedia webpage to PDF with both libraries.

  • Professional License: This license is suitable for larger teams, supporting ten developers, ten locations, and ten projects for $2,999. It offers the same contact support channels as the previous tiers but also offers screen-sharing support.

  • Royalty-free redistribution: IronPDF's licensing also offers royalty-free redistribution coverage for an extra $1,999

  • Uninterrupted product support: IronPDF offers access to ongoing product updates, security feature upgrades, and support from their engineering team for either $999/year or a one-time purchase of $1,999 for a 5-year coverage.

  • Iron Suite: For $1,498, you get access to all Iron Software products including IronPDF, IronOCR, IronWord, IronXL, IronBarcode, IronQR, IronZIP, IronPrint, and IronWebScraper.

Itextsharp 2 related to IronPDF Pricing and Licensing

iTextSharp Licensing

  • AGPL License: iTextSharp is available for free under the AGPL (Affero General Public License). This license requires that any software using iTextSharp be open-source under the same license if it is redistributed.

  • Commercial License: For projects that don't meet AGPL terms, iTextSharp offers a commercial license to allow its use in proprietary software. Pricing for this license is based on a quote-based model and varies depending on the usage and scope of the project.

Documentation and Support: IronPDF vs. iText

IronPDF

  • Comprehensive Documentation: Extensive and user-friendly documentation covering all the features it has to offer.

  • 24/5 Support: Active engineer support is available.

  • Video Tutorials: Step-by-step video guides are available on YouTube.

  • Community Forum: Engaged community for additional support.

  • Regular Updates: Monthly product updates to ensure the latest features and security patches.

iTextSharp

  • Documentation: iTextSharp offers detailed documentation covering its key functionalities.

  • Examples and Tutorials: A variety of tutorials and code examples are provided to help developers get started.

  • GitHub: Developers can submit issues or bugs to the iTextSharp GitHub repository and interact with the iTextSharp community for support.

  • Updates: Regular updates are provided to improve features and address bugs.

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

Conclusion

Both IronPDF and iTextSharp are solid options for PDF manipulation in .NET projects. IronPDF distinguishes itself with its intuitive platform integration and features like HTML-to-PDF conversion and advanced security options. iTextSharp, while rooted in the open-source iText library, offers a powerful and flexible toolset under the AGPL and commercial licenses, making it ideal for projects that can benefit from open-source flexibility or require strict licensing compliance.

Choosing the right tool depends on your project’s licensing requirements, technical support needs, and specific feature demands. Whether you favor the simplicity and comprehensive support of IronPDF or the open-source robustness of iTextSharp, both libraries offer developers ample resources to enhance PDF workflows in their applications.


Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

< PREVIOUS
IronPDF and EvoPdf: A Comparison
NEXT >
Syncfusion PDF Viewer Comparison for HTML to PDF

Ready to get started? Version: 2024.12 just released

Free NuGet Download Total downloads: 11,810,873 View Licenses >