Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
A decent and simple tool for manipulating PDFs can streamline many tasks and processes that are involved in creating and editing PDF documents. In the .NET ecosystem, there are two popular libraries – IronPDF and iText– that allow for PDF generation without any Adobe dependencies. They both have a variety of features such as creating, editing, converting, etc., but this article will focus on comparing these libraries based on three criteria: the ability of the features they have to offer, documentation quality provided by them, pricing policy adopted by these companies for using their products.
IronPDF is a prominent .NET PDF library that allows programmers to easily create, modify, and interact with PDF documents. It can be used in different .NET environments, including Core, 8, 7, 6, and Framework, which makes it highly flexible for various development requirements. The key feature of IronPDF is its rich feature set, such as HTML to PDF conversion, an ability to merge PDFs, PDF encryption, and application of digital signatures, among others. The documentation is written in a way that users can understand without any difficulties while the library itself has strong technical support.
iText is one of the most popular PDF libraries available for Java as well as .NET (C#). iText Core 8 offers an enterprise-level programmable solution for creating and manipulating PDF files. iText provides support for many different features and is released under both open-source (AGPL) licenses and commercial licenses. This means it’s able to cover a wide range of use cases during digital transformation projects thanks to its versatility.
IronPDF and iText are compatible with various platforms; they can process PDFs across many different systems as well as within the .NET framework. Because of this, we will compare the supported frameworks and platforms for each product below.
IronPDF Overview of Supported Platforms supports a wide range of platforms and environments, ensuring seamless integration and deployment in various systems:
.NET versions:
(C#, VB.NET, F#)
.NET Core (8, 7, 6, 5, and 3.1+)
.NET Standard (2.0+)
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
.NET versions:
.NET Core (2.x, 3.x)
.NET Framework (4.6.1+)
App environments: iText supports a range of app environments, thanks to its support for both Java and .NET (C#), these include; Windows, Mac, Linux, and Docker.
IronPDF Key Feature List and iText 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 look at some of these features and how the two libraries compare when it comes to carrying out different PDF-related tasks.
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.
For more information on the extensive set of features IronPDF has to offer, visit the IronPDF features page.
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.
Converting HTML content into PDF using IronPDF 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")
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
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. iText, takes a basic approach, using its HtmlConverter class to create PDF documents from an HTML file.
Encrypting PDF Files with IronPDF 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 iText 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")
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
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, iText employs a lower-level and longer method where PDF encryption is applied during document creation, specifying owner and user passwords along with permissions like printing rights using encryption standards like AES-128.
Occasionally, while handling confidential or private information, it may be necessary to redact text in PDF with IronPDF portions of a PDF file. The code examples below will demonstrate how you can redact text using IronPDF in comparison with 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")
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) }; // 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
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.
iText, on the other hand, doesn't offer a built-in redaction tool in the same sense as IronPDF. However, it can still cover sensitive data using the method shown above to draw over the content users wish to redact. This can lead to issues, however, as these rectangles don't actually remove or properly redact the text, meaning other people could potentially copy and paste the data trying to be redacted.
Being able to digital sign PDF documents with IronPDF such as PDF files and then making it an automated process could be time saving. Here are some pieces of code that will compare how IronPDF differs from iText in terms of carry out digital signing of documents.
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")
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
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. iText requires a longer, more complex process to apply digital signatures to PDF files, and while their ability to use different interface options and keys does offer more control to the user, the complexity of how this tool carries out this task could impede it.
The ability to add and personalize watermarks on PDFs with IronPDF 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 iText 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")
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();
// 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
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. iText's approach to adding watermarks to PDFs requires more manual work to carry out the task, which can slow the process down.
There are moments when PDF pages need to be stamped with text or images on a PDF, similar to how one might need to apply watermarks to their PDF files. We will now compare how IronPDF and iText perform stamping content on a PDF document.
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")
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
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. iText 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.
Sometimes, you might have to convert PDFs from one format to the other. In this case, we looking at DOCX to PDF conversion with IronPDF and comparing how IronPDF and iText 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")
iText
iText, on its own, cannot handle DOCX to PDF conversion; instead, it relies on outside libraries such as DocX or Aspose.Words
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. iText, on the other hand, relies on external libraries in order to carry out this task.
For more detailed examples, visit IronPDF Examples of Creating PDFs from HTML.
IronPDF Licensing Options has different levels and additional features for purchasing a license. Developers can also buy IronSuite 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 version 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.
Plus License: Supporting three developers, three locations, and three projects, this is the next step up from the lite license and costs $1,499. The Plus license offers chat support and phone support in addition to basic email support.
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.
AGPL License: The iText Core library is open-sourced and available to users for free. To use iText under this licensing model, users must comply with its terms and any modifications made to iText under this license must also be released under the AGPL licensing model.
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.
Documentation: In-depth documentation covering the features offered by iText software.
Examples and tutorials: Has tutorials on how to use its various features alongside code examples.
GitHub: Developers can easily submit any issues or bugs they come across to the iText GitHub repository and communicate with the iText group
For more details on IronPDF documentation and support, visit IronPDF Documentation and the Iron Software YouTube Channel.
In the realm of PDF manipulation tools for .NET, both IronPDF and iText offer robust capabilities tailored to various development needs. IronPDF stands out with its straightforward integration across a wide array of platforms, including .NET Core, Framework, and Standard, alongside comprehensive features like HTML to PDF conversion and advanced security options. On the other hand, iText, renowned for its Java heritage, provides powerful PDF generation and manipulation tools under both open-source and commercial licenses, emphasizing versatility and customization.
Choosing between these tools ultimately hinges on project requirements, licensing preferences, and the level of technical support needed. Whether opting for the simplicity and flexibility of IronPDF or the extensive feature set of the open-source PDF library that is iText, developers have ample resources to streamline PDF workflows effectively in their applications.
You can try the 30-day free trial to check out their available features.
9 .NET API products for your office documents