PRODUCT COMPARISONS

SpirePDF C# HTML to PDF Tutorial & Library Comparison

Published November 11, 2024
Share:

Introduction

Are you looking for a PDF library to carry out all your PDF-related tasks without installing Adobe Acrobat, but don't know which one to choose out of the numerous PDF libraries that are currently out there? Today, we will be taking a closer look at two prominent PDF libraries, IronPDF and Spire.PDF, within the .NET environment.

Throughout this comparison guide, we be looking at the features these libraries offer, how they can help you, the documentation on hand for the libraries, and the pricing for licensing to use these libraries.

A Brief Overview of IronPDF and Spire.PDF

IronPDF is a versatile .NET PDF library designed to handle a wide range of PDF-related tasks, including converting PDF files, PDF editing, PDF creation, reading PDF files, and more. It is known for its ease of integration into existing .NET applications, high performance, and support for modern web standards like HTML5, CSS3, and JavaScript. IronPDF's API is intuitive, making it an excellent choice if you are looking to add robust PDF functionality to your projects.

Spire.PDF for .NET is another powerful .NET PDF library that provides a comprehensive set of features for PDF creation and manipulation. It supports various PDF functionalities such as text and image extraction, PDF form filling, and digital signatures. Spire.PDF is designed to be easy to use and integrates seamlessly with .NET applications, making it another potential candidate for your PDF projects.

For more detailed information about IronPDF, visit IronPDF.com.

Cross-Platform Compatibility

IronPDF

IronPDF stands out with its extensive cross-platform compatibility. It supports a wide range of environments within the .NET framework, ensuring seamless operation across different platforms. Below is a summary of IronPDF's platform compatibility:

  • .NET versions:

    • Fully written in and supports C#, VB.NET, and F#

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

    • .NET Standard (2.0+)

    • .NET Framework (4.6.2+)
  • App environments: IronPDF works within various app environments such as 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

For more details on IronPDF's compatibility, visit IronPDF Compatibility.

Spire.PDF

Spire.PDF has full support within the .NET environment, but while it works within the Windows operating system, it lacks the native support for Linux and macOS that IronPDF has.

  • .NET Support:

    • .NET Framework 2.0+

    • .NET Core 2.0+

    • Written C#, with support for VB.NET
  • App Environments: Spire.PDF works in various app environments such as Windows and ASP.NET applications, it can also support Windows Forms.

Feature Comparison: PDF Functionality in IronPDF vs. Spire.PDF

IronPDF and Spire.PDF both offer a range of features tailored for different PDF functionalities. Below is a comparison of key features provided by each library:

IronPDF Features

  • PDF conversion: IronPDF can convert HTML to PDF, with its full support for modern web standards, you can be assured that IronPDF will consistently return pixel-perfect PDFs from your HTML content. IronPDF can also convert PDF files from other formats such as DOCX, images, RTF, and more.

  • PDF Generation: With IronPDF, you can generate PDFs from URLs, ASPX files, or HTML strings.

  • Security features: With IronPDF, you can always be assured that any sensitive PDF files are secure thanks to its security features. Use IronPDF to encrypt your PDF files, set passwords, and set permissions for your PDF files.

  • PDF editing features: With IronPDF you can process existing PDF documents, edit them, and read PDF files with ease. IronPDF offers editing features such as adding headers and footers, stamping text and images onto the PDF pages, adding custom watermarks to the PDF, working with PDF forms, and splitting or merging PDF files.

  • Integration: Seamlessly integrates with ASP.NET and MVC applications.

  • PDF version support: Can support PDF version 1.2-1.7

For a comprehensive list of IronPDF features, visit IronPDF Features.

Spire.PDF Features

  • PDF Creation: Create PDFs from scratch or existing files.

  • Text and Image Extraction: Use Spire.PDF to extract PDF pages and content.

  • PDF Form Handling: Fill and manage PDF forms.

  • PDF Conversion: Convert PDFs to other formats like HTML, RTF, and images.

  • Page Manipulation: Insert, delete, and reorder pages in a PDF.

Comparison of Top Highlight Features with Code Examples Between IronPDF vs. Spire.PDF for .NET

To illustrate the capabilities of IronPDF and Spire.PDF for .NET, we will compare their implementation of several key PDF functionalities through code examples, giving you an idea of how these features could help with your PDF projects.

Convert HTML to PDF

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#

Spire.PDF Example:

using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
using System.Drawing;

namespace ConvertHtmlStringToPdfWithoutPlugin
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            //Create a PdfPageSettings object
            PdfPageSettings setting = new PdfPageSettings();

            //Save page size and margins through the object
            setting.Size = new SizeF(1000, 1000);
            setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);

            //Create a PdfHtmlLayoutFormat object
            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            //Set IsWaiting property to true
            htmlLayoutFormat.IsWaiting = true;

            //Read html string from a .html file
            string htmlString = File.ReadAllText(@"C:\Users\Administrator\Desktop\Document\Html\Sample.html");
            //Load HTML from html string using LoadFromHTML method
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            //Save to a PDF file
            doc.SaveToFile("HtmlStringToPdf.pdf");
        }
    }
}
using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
using System.Drawing;

namespace ConvertHtmlStringToPdfWithoutPlugin
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            //Create a PdfPageSettings object
            PdfPageSettings setting = new PdfPageSettings();

            //Save page size and margins through the object
            setting.Size = new SizeF(1000, 1000);
            setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);

            //Create a PdfHtmlLayoutFormat object
            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            //Set IsWaiting property to true
            htmlLayoutFormat.IsWaiting = true;

            //Read html string from a .html file
            string htmlString = File.ReadAllText(@"C:\Users\Administrator\Desktop\Document\Html\Sample.html");
            //Load HTML from html string using LoadFromHTML method
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            //Save to a PDF file
            doc.SaveToFile("HtmlStringToPdf.pdf");
        }
    }
}
Imports Spire.Pdf
Imports Spire.Pdf.HtmlConverter
Imports System.IO
Imports System.Threading
Imports System.Drawing

Namespace ConvertHtmlStringToPdfWithoutPlugin
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			'Create a PdfDocument object
			Dim doc As New PdfDocument()

			'Create a PdfPageSettings object
			Dim setting As New PdfPageSettings()

			'Save page size and margins through the object
			setting.Size = New SizeF(1000, 1000)
			setting.Margins = New Spire.Pdf.Graphics.PdfMargins(20)

			'Create a PdfHtmlLayoutFormat object
			Dim htmlLayoutFormat As New PdfHtmlLayoutFormat()

			'Set IsWaiting property to true
			htmlLayoutFormat.IsWaiting = True

			'Read html string from a .html file
			Dim htmlString As String = File.ReadAllText("C:\Users\Administrator\Desktop\Document\Html\Sample.html")
			'Load HTML from html string using LoadFromHTML method
			Dim thread As New Thread(Sub()
				doc.LoadFromHTML(htmlString, True, setting, htmlLayoutFormat)
			End Sub)
			thread.SetApartmentState(ApartmentState.STA)
			thread.Start()
			thread.Join()

			'Save to a PDF file
			doc.SaveToFile("HtmlStringToPdf.pdf")
		End Sub
	End Class
End Namespace
VB   C#

IronPDF uses Chrome's rendering engine for high-fidelity HTML to PDF conversion, ensuring an accurate representation of web content thanks to its support for modern web standards. Spire.PDF also provides robust HTML to PDF conversion but may not match the rendering precision of IronPDF, and takes a longer, more manual approach.

So if you are looking for an easy method for automating your HTML to PDF tasks while maintaining a high quality for your PDFs then IronPDF would be the tool for you.

Encrypting PDF Documents

IronPDF:

using IronPdf;
using System;

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

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

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

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

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

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

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

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

' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")

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

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

' Change or set the document encryption password
pdf.Password = "my-password"
pdf.SaveAs("secured.pdf")
VB   C#

Spire.PDF:

using Spire.Pdf;
using Spire.Pdf.Security;

//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

//Load a sample PDF file
pdf.LoadFromFile(@"E:\Files\sample.pdf");

//Encrypt the PDF file with password
pdf.Security.Encrypt("open", "permission", PdfPermissionsFlags.Print | PdfPermissionsFlags.CopyContent, PdfEncryptionKeySize.Key128Bit);

//Save the result file
pdf.SaveToFile("Encrypt.pdf", FileFormat.PDF);
using Spire.Pdf;
using Spire.Pdf.Security;

//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

//Load a sample PDF file
pdf.LoadFromFile(@"E:\Files\sample.pdf");

//Encrypt the PDF file with password
pdf.Security.Encrypt("open", "permission", PdfPermissionsFlags.Print | PdfPermissionsFlags.CopyContent, PdfEncryptionKeySize.Key128Bit);

//Save the result file
pdf.SaveToFile("Encrypt.pdf", FileFormat.PDF);
Imports Spire.Pdf
Imports Spire.Pdf.Security

'Create a PdfDocument object
Private pdf As New PdfDocument()

'Load a sample PDF file
pdf.LoadFromFile("E:\Files\sample.pdf")

'Encrypt the PDF file with password
pdf.Security.Encrypt("open", "permission", PdfPermissionsFlags.Print Or PdfPermissionsFlags.CopyContent, PdfEncryptionKeySize.Key128Bit)

'Save the result file
pdf.SaveToFile("Encrypt.pdf", FileFormat.PDF)
VB   C#

Both libraries provide easy-to-use methods for encrypting PDFs, and setting the encrypted PDF documents' readability. IronPDF offers a straightforward approach while still giving you full control over the security settings of your PDF. Spire.PDF takes a slightly shorter process but still includes additional options for setting permissions.

Redacting PDF Content

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#

Spire.PDF:

Spire.PDF has no dedicated redaction tool built into it. However, you can still use it to redact content by either drawing a rectangle over the content you wish to redact (as seen below) or by extracting and removing the text you want to redact.

using Spire.Pdf;
using Spire.Pdf.Graphics;

// Specify the input PDF file path
        string inputPdfFilePath = "path/to/your/input.pdf";

        // Specify the output redacted PDF file path
        string outputPdfFilePath = "path/to/your/redacted_output.pdf";

        // Create a new PdfDocument object
        PdfDocument pdfDocument = new PdfDocument();

        // Load the existing PDF document
        pdfDocument.LoadFromFile(inputPdfFilePath);

        // Redact content on each page
        foreach (PdfPageBase page in pdfDocument.Pages)
        {
            // Define the area to redact (e.g., coordinates and size of the rectangle)
            RectangleF redactArea = new RectangleF(100, 100, 200, 50); // Example coordinates and size

            // Apply redaction
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.Black), redactArea);
        }      
        // Save the redacted PDF document
        pdfDocument.SaveToFile(outputPdfFilePath);
using Spire.Pdf;
using Spire.Pdf.Graphics;

// Specify the input PDF file path
        string inputPdfFilePath = "path/to/your/input.pdf";

        // Specify the output redacted PDF file path
        string outputPdfFilePath = "path/to/your/redacted_output.pdf";

        // Create a new PdfDocument object
        PdfDocument pdfDocument = new PdfDocument();

        // Load the existing PDF document
        pdfDocument.LoadFromFile(inputPdfFilePath);

        // Redact content on each page
        foreach (PdfPageBase page in pdfDocument.Pages)
        {
            // Define the area to redact (e.g., coordinates and size of the rectangle)
            RectangleF redactArea = new RectangleF(100, 100, 200, 50); // Example coordinates and size

            // Apply redaction
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.Black), redactArea);
        }      
        // Save the redacted PDF document
        pdfDocument.SaveToFile(outputPdfFilePath);
Imports Spire.Pdf
Imports Spire.Pdf.Graphics

' Specify the input PDF file path
		Private inputPdfFilePath As String = "path/to/your/input.pdf"

		' Specify the output redacted PDF file path
		Private outputPdfFilePath As String = "path/to/your/redacted_output.pdf"

		' Create a new PdfDocument object
		Private pdfDocument As New PdfDocument()

		' Load the existing PDF document
		pdfDocument.LoadFromFile(inputPdfFilePath)

		' Redact content on each page
		For Each page As PdfPageBase In pdfDocument.Pages
			' Define the area to redact (e.g., coordinates and size of the rectangle)
			Dim redactArea As New RectangleF(100, 100, 200, 50) ' Example coordinates and size

			' Apply redaction
			page.Canvas.DrawRectangle(New PdfSolidBrush(Color.Black), redactArea)
		Next page
		' Save the redacted PDF document
		pdfDocument.SaveToFile(outputPdfFilePath)
VB   C#

IronPDF simplifies redaction with its robust, yet straightforward, redaction tool. Spire.PDF requires manual handling of redaction because it lacks a built-in redaction tool, which would be less efficient.

Sign PDF

IronPDF:

using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");

// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);

// Create PDF digital signature with the PdfSignature object
var sig = new PdfSignature(cert);

// Sign PDF document
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");

// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);

// Create PDF digital signature with the PdfSignature object
var sig = new PdfSignature(cert);

// Sign PDF document
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates

Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>foo</h1>")

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

' Create PDF digital signature with the PdfSignature object
Private sig = New PdfSignature(cert)

' Sign PDF document
pdf.Sign(sig)
pdf.SaveAs("signed.pdf")
VB   C#

Spire.PDF Example:

using system;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Security;
using Spire.Pdf.Graphics;

//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
24
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 260 - 54 , 200, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;

//Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;

//Set the signature content
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

//Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handwrittingSignature.png");

//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));

//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

//Save to file
doc.SaveToFile("VisiableSignature.pdf");
doc.Close();
using system;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Security;
using Spire.Pdf.Graphics;

//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
24
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 260 - 54 , 200, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;

//Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;

//Set the signature content
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

//Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handwrittingSignature.png");

//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));

//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

//Save to file
doc.SaveToFile("VisiableSignature.pdf");
doc.Close();
Imports system
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Security
Imports Spire.Pdf.Graphics

'Create a PdfDocument object
Private doc As New PdfDocument()

'Load a sample PDF file
doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")

'Load the certificate
Dim cert As New PdfCertificate("C:\Users\Administrator\Desktop\MyCertificate.pfx", "e-iceblue")

'Create a PdfSignature object and specify its position and size
Dim signature As New PdfSignature(doc, doc.Pages(doc.Pages.Count - 1), cert, "MySignature")
24 RectangleF rectangleF = New RectangleF(doc.Pages(0).ActualSize.Width - 260 - 54, 200, 260, 110)
signature.Bounds = rectangleF
signature.Certificated = True

'Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail

'Set the signature content
signature.NameLabel = "Signer:"
signature.Name = "Gary"
signature.ContactInfoLabel = "Phone:"
signature.ContactInfo = "0123456"
signature.DateLabel = "Date:"
signature.Date = DateTime.Now
signature.LocationInfoLabel = "Location:"
signature.LocationInfo = "USA"
signature.ReasonLabel = "Reason:"
signature.Reason = "I am the author"
signature.DistinguishedNameLabel = "DN:"
signature.DistinguishedName = signature.Certificate.IssuerName.Name

'Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\Users\Administrator\Desktop\handwrittingSignature.png")

'Set the signature font
signature.SignDetailsFont = New PdfTrueTypeFont(New Font("Arial Unicode MS", 12F, FontStyle.Regular))

'Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges Or PdfCertificationFlags.AllowFormFill

'Save to file
doc.SaveToFile("VisiableSignature.pdf")
doc.Close()
VB   C#

Digitally signing PDFs can be helpful in various settings from being used to authenticate PDF documents, to simply signing off on a new project. IronPDF offers a straightforward approach to adding digital signatures, with IronPDF you can easily automate the digital signature process. Spire.PDF also supports digital signatures for PDFs, however the process can be more manual and take more work to implement.

Watermark PDF

IronPDF:

using IronPdf;

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

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
using IronPdf;

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

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf

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

Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("C:\Path\To\Watermarked.pdf")
VB   C#

Spire.PDF Example:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

//Load a sample PDF document
pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

//Create a PdfTrueTypeFont object
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 50f), true);

//Set the watermark text
string text = "CONFIDENTIAL";

//Measure the text size
SizeF textSize = font.MeasureString(text);

            //Calculate the values of two offset variables,
            //which will be used to calculate the translation amount of the coordinate system
float offset1 = (float)(textSize.Width * System.Math.Sqrt(2) / 4);
float offset2 = (float)(textSize.Height * System.Math.Sqrt(2) / 4);

        //Traverse all the pages in the document
    foreach (PdfPageBase page in pdf.Pages)
        {
    //Set the page transparency
    page.Canvas.SetTransparency(0.8f);

    //Translate the coordinate system by specified coordinates
    page.Canvas.TranslateTransform(page.Canvas.Size.Width / 2 - offset1 - offset2, page.Canvas.Size.Height / 2 + offset1 - offset2);

        //Rotate the coordinate system 45 degrees counterclockwise
        page.Canvas.RotateTransform(-45);

        //Draw watermark text on the page
        page.Canvas.DrawString(text, font, PdfBrushes.DarkGray, 0, 0);
            }

//Save the changes to another file
pdf.SaveToFile("TextWatermark.pdf");
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

//Load a sample PDF document
pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

//Create a PdfTrueTypeFont object
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 50f), true);

//Set the watermark text
string text = "CONFIDENTIAL";

//Measure the text size
SizeF textSize = font.MeasureString(text);

            //Calculate the values of two offset variables,
            //which will be used to calculate the translation amount of the coordinate system
float offset1 = (float)(textSize.Width * System.Math.Sqrt(2) / 4);
float offset2 = (float)(textSize.Height * System.Math.Sqrt(2) / 4);

        //Traverse all the pages in the document
    foreach (PdfPageBase page in pdf.Pages)
        {
    //Set the page transparency
    page.Canvas.SetTransparency(0.8f);

    //Translate the coordinate system by specified coordinates
    page.Canvas.TranslateTransform(page.Canvas.Size.Width / 2 - offset1 - offset2, page.Canvas.Size.Height / 2 + offset1 - offset2);

        //Rotate the coordinate system 45 degrees counterclockwise
        page.Canvas.RotateTransform(-45);

        //Draw watermark text on the page
        page.Canvas.DrawString(text, font, PdfBrushes.DarkGray, 0, 0);
            }

//Save the changes to another file
pdf.SaveToFile("TextWatermark.pdf");
Imports System
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing

'Create a PdfDocument object
Private pdf As New PdfDocument()

'Load a sample PDF document
pdf.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")

'Create a PdfTrueTypeFont object
Dim font As New PdfTrueTypeFont(New Font("Arial", 50F), True)

'Set the watermark text
Dim text As String = "CONFIDENTIAL"

'Measure the text size
Dim textSize As SizeF = font.MeasureString(text)

			'Calculate the values of two offset variables,
			'which will be used to calculate the translation amount of the coordinate system
Dim offset1 As Single = CSng(textSize.Width * Math.Sqrt(2) / 4)
Dim offset2 As Single = CSng(textSize.Height * Math.Sqrt(2) / 4)

		'Traverse all the pages in the document
	For Each page As PdfPageBase In pdf.Pages
	'Set the page transparency
	page.Canvas.SetTransparency(0.8F)

	'Translate the coordinate system by specified coordinates
	page.Canvas.TranslateTransform(page.Canvas.Size.Width \ 2 - offset1 - offset2, page.Canvas.Size.Height \ 2 + offset1 - offset2)

		'Rotate the coordinate system 45 degrees counterclockwise
		page.Canvas.RotateTransform(-45)

		'Draw watermark text on the page
		page.Canvas.DrawString(text, font, PdfBrushes.DarkGray, 0, 0)
	Next page

'Save the changes to another file
pdf.SaveToFile("TextWatermark.pdf")
VB   C#

IronPDF provides an easy method for adding text watermarks while giving you full control over the position and design of the watermark. IronPDF's use of HTML and CSS means that if you have experience with these languages, the process is even easier. Spire.PDF's approach is longer with more of a manual process but still provides a strong watermarking tool with full control over the design and position.

Stamping Image HTML Text

IronPDF:

using IronPdf;
using IronPdf.Editing;

// Instantiate Renderer
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;

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

' Instantiate Renderer
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#

Spire.PDF:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

//save graphics state
PdfGraphicsState state = page.Canvas.Save();

//Draw the text - transform          
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);
page.Canvas.TranslateTransform(20, 200);
page.Canvas.ScaleTransform(1f, 0.6f);
page.Canvas.SkewTransform(-10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);
page.Canvas.SkewTransform(10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);
page.Canvas.ScaleTransform(1f, -1f);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);

//restore graphics
page.Canvas.Restore(state);
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

//save graphics state
PdfGraphicsState state = page.Canvas.Save();

//Draw the text - transform          
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);
page.Canvas.TranslateTransform(20, 200);
page.Canvas.ScaleTransform(1f, 0.6f);
page.Canvas.SkewTransform(-10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);
page.Canvas.SkewTransform(10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);
page.Canvas.ScaleTransform(1f, -1f);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);

//restore graphics
page.Canvas.Restore(state);
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing

'save graphics state
Private state As PdfGraphicsState = page.Canvas.Save()

'Draw the text - transform          
Private font As New PdfFont(PdfFontFamily.Helvetica, 18F)
Private brush1 As New PdfSolidBrush(Color.DeepSkyBlue)
Private brush2 As New PdfSolidBrush(Color.CadetBlue)
page.Canvas.TranslateTransform(20, 200)
page.Canvas.ScaleTransform(1F, 0.6F)
page.Canvas.SkewTransform(-10, 0)
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0)
page.Canvas.SkewTransform(10, 0)
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0)
page.Canvas.ScaleTransform(1F, -1F)
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18)

'restore graphics
page.Canvas.Restore(state)
VB   C#

IronPDF's text and image stamping tool is a powerful, easy-to-use stamping tool that uses an approach similar to HTML and CSS when you apply the stamped content. While Spire.PDF also offers a basic text stamping tool, it takes more work to apply the stamped text to your PDF files.

DOCX to PDF

IronPDF:

using IronPdf;

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

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

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

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

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

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

' Instantiate Renderer
Private renderer As New DocxToPdfRenderer()

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

' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")
VB   C#

Spire.PDF:

Spire.PDF itself cannot convert DOCX to PDF, however, the Spire.Doc library can be used to handle this conversion, and then you can go on to use Spire.PDF to work on the resultant PDF.

using Spire.Doc;

// Create a Document object
Document doc = new Document();

// Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.docx");

// Save the document to PDF
doc.SaveToFile("ToPDF.pdf", FileFormat.PDF);

// Dispose resources
doc.Dispose();
using Spire.Doc;

// Create a Document object
Document doc = new Document();

// Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.docx");

// Save the document to PDF
doc.SaveToFile("ToPDF.pdf", FileFormat.PDF);

// Dispose resources
doc.Dispose();
Imports Spire.Doc

' Create a Document object
Private doc As New Document()

' Load a Word document
doc.LoadFromFile("C:\Users\Administrator\Desktop\Sample.docx")

' Save the document to PDF
doc.SaveToFile("ToPDF.pdf", FileFormat.PDF)

' Dispose resources
doc.Dispose()
VB   C#

IronPDF offers built-in support for direct DOCX to PDF conversion, meaning you save time by not having to install additional libraries to handle this task. Spire.PDF, on the other hand, cannot handle the direct conversion of DOCX to PDF, so you would need to install the Spire.Doc library to convert your DOCX files to PDF.

Summary of the Code Examples Comparison

Below is a comparison table summarizing the key differences in code implementation between IronPDF and Spire.PDF for .NET:

Pricing and Licensing: IronPDF vs. Spire.PDF for .NET Library

IronPDF Pricing and Licensing

IronPDF has different levels and additional features for purchasing a license. Developers can also buy IronSuite which, gives you access to all of IronSoftware’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.

  • 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.

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

Spire.PDF

Spire.PDF offers a range of licenses depending on your needs.

  • Free version: Spire.PDF does offer a free version, this totally free PDF API is limited to 10 PDF pages, beyond this you would need to purchase a paid license.

  • Developer Subscription: Priced at either $999 or $1,199 per year depending on the type of support you need, this option is for developers who need to build PDF-related features but don’t require OEM distribution rights.

  • Developer OEM Subscription: Costs around $2,549 - $4,248 per year depending on the amount of support you need, and includes free upgrades, premium support, and the ability to distribute the application to end-users.

  • Site Small Business: Priced at either $4,599 or $7,598 depending on the support you want, this licensing tier supports up to 10 developers across up to 10 locations, updates for 1 year, and free online technical resources.

  • Site OEM Subscription: Costs $13,088 - $16,687 per year again depending on the type of support you need, and is aimed at larger enterprises that need to deploy applications to multiple locations.

Documentation and Support: IronPDF vs. Spire.PDF for .NET

IronPDF

IronPDF excels in providing extensive documentation and support:

  • Comprehensive Documentation: Extensive and user-friendly documentation covering all features.

  • 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.

  • PDF API reference: Offers API references so you can get the most out of what our tools have to offer.

For more information, check out IronPDF's extensive documentation, and visit the IronSoftware YouTube Channel.

Spire.PDF for .NET Documentation and Support

  • Forums: Spire.PDF has a forum where users can interact with one another sharing tips, uses, and issues they come across in Spire.PDF.

  • Code Samples: Spire.PDF has code examples for you to find on their website, showing how to use the product in various use cases.

  • Newsletters: Spire.PDF offers a developer's newsletter for update announcements and other important information.

  • Support: Spire.PDF offers different levels of support and response times depending on what licensing version you hold.

Conclusion

In conclusion, IronPDF and Spire.PDF for .NET are powerful tools for handling PDF documents in .NET applications. IronPDF excels in ease of use, cross-platform compatibility, and support for modern web standards, making it a preferred choice if you are looking to step up your game when working with PDF documents. Spire.PDF offers a comprehensive set of features but may require more effort for complex tasks, and may lack the rich, extensive set of features that IronPDF has to offer.

You can try the 30-day free trial to check out their available features.

< PREVIOUS
ActivePDF DocConverter Tutorial and Comparison to IronPDF
NEXT >
PDFSharp HTML to PDF Example and Tutorials Comparison

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 11,308,499 View Licenses >