PRODUCT COMPARISONS

A Comparison Between Compdfkit & IronPDF

Published August 13, 2024
Share:

PDF, short for Portable Document Format, is a file type created by Adobe to ensure uniformity in document sharing. This format keeps the layout, text, and images consistent across various devices and operating systems. PDFs are known for their security, interactive features, and compact size, making them perfect for distributing documents without altering the original content.

For developers using C#, PDF libraries provide PDF Solutions for working with PDF files. These libraries enable document creation, content modification, and the extraction of text and images. They also support features like form handling, digital signatures, and compatibility across different platforms. Designed for optimal performance, these libraries facilitate efficient PDF processing.

In this article, we will compare two C# PDF libraries: IronPDF and ComPDFKit. This comparison will cover features, functionality, code examples, and licensing. By examining these aspects, you can determine which library best suits your PDF-related projects.

1. ComPDFKit SDK

A Comparison Between Compdfkit & IronPDF: Figure 1 - ComPDFKIT SDK homepage

ComPDFKit PDF SDK is a robust C# PDF SDK that allows developers to integrate comprehensive PDF functionalities into their applications. This library supports a wide range of PDF functions necessary for handling PDF documents programmatically. It is designed for use in various environments, including web, desktop, and mobile platforms, making it a versatile tool for developers working on cross-platform projects. It has multiple functions in the example solution. You can select any related ComPDFKit PDF SDK function that you want to try.

1.1 Key Features of ComPDFKit

  1. PDF Viewing: ComPDFKit provides a powerful PDF viewer that allows users to view PDF documents with high fidelity. The viewer supports smooth scrolling, zooming, and navigation, ensuring a seamless user experience.
  2. Annotations: The library includes tools to integrate PDF annotations smoothly. Users can highlight text, add comments, and create various types of annotations, which are essential for collaborative workflows.
  3. Form Handling: The library offers extensive support for interactive forms. Developers can create, fill, and extract data from PDF forms, making it ideal for applications that require form processing.
  4. PDF Editing: ComPDFKit allows for extensive PDF editing capabilities, including modifying text, images, and other content within PDF files. This feature is useful for applications that need to update or customize existing PDF documents.
  5. Conversion: The library supports converting PDF files to and from various formats such as Word, Excel, PowerPoint, and images. This flexibility is vital for applications that need to transform PDF content for different uses.
  6. Security: ComPDFKit includes robust security features such as encryption and permissions management. Developers can secure PDF documents to protect sensitive information from unauthorized access.
  7. Optical Character Recognition (OCR): The library includes OCR capabilities to convert scanned documents into editable and searchable PDFs. This feature is essential for digitizing paper documents and making them accessible electronically.

ComPDFKit provides a comprehensive set of APIs that streamline the integration of these features into various applications. Its extensive documentation and support make it an excellent choice for developers looking to incorporate advanced PDF functionalities into their projects

2. IronPDF Library

A Comparison Between Compdfkit & IronPDF: Figure 2 - IronPDF homepage

IronPDF is a versatile PDF library for .NET that allows developers to create, edit, and manage PDF documents using C#. It provides comprehensive PDF functions. It is designed to simplify PDF generation by rendering PDFs from HTML, CSS, JavaScript, and various image formats. This makes it an ideal tool for developers looking to integrate robust PDF functionality into their .NET applications.

Key Features of IronPDF

  1. HTML to PDF Conversion: IronPDF excels in converting HTML, CSS, and JavaScript content into high-quality PDF documents. This feature supports generating PDFs from HTML strings, URLs, ASPX webforms, and MVC views, making it a flexible solution for various web-based content.
  2. PDF Editing: The library offers extensive editing capabilities, including adding, copying, and deleting pages, merging and splitting PDFs, and manipulating text and images. Developers can also add headers, footers, watermarks, and digital signatures to PDF documents.
  3. Form Handling: IronPDF supports smart forms creating and filling out PDF forms programmatically. This feature is essential for applications that require dynamic form generation and data extraction from user-submitted forms.
  4. Security Features: IronPDF provides robust security options, such as setting passwords and permissions, encrypting documents, and adding digital signatures. These features ensure that sensitive information within PDF documents is protected against unauthorized access.
  5. OCR and Data Extraction: The library includes Optical Character Recognition (OCR) capabilities, allowing the conversion of scanned documents into editable and searchable PDFs. Additionally, IronPDF can extract text, images, and other data from existing PDFs, facilitating content reuse and analysis.
  6. Image Conversion: IronPDF supports converting various image formats, including JPG, PNG, GIF, BMP, and SVG, into PDF documents. It also offers the ability to render PDF pages as images, which is useful for applications requiring visual previews of PDF content.
  7. Cross-Platform Compatibility: IronPDF is compatible with multiple .NET platforms, including .NET Core, .NET Framework, and .NET Standard. It supports deployment on Windows, Linux, macOS, and Azure, making it a versatile choice for developers working in diverse environments.
  8. Performance Optimization: The library is designed for high performance, with support for multithreading and asynchronous operations. This ensures that PDF processing tasks are executed efficiently, even in applications with high workloads.
  9. Comprehensive Documentation and Support: IronPDF provides detailed documentation and numerous code examples, making it easy for developers to get started and implement its features. Additionally, it offers technical support to assist with any issues that may arise during development.

3. Create a New Visual Studio Project

Before we delve into coding examples, let’s create a new Visual Studio project. Here’s a step-by-step guide to setting up a C# console application in Visual Studio.

Step 1: Install Visual Studio (If Not Already Installed)

Visual Studio is the best IDE for C# projects. If you haven't downloaded and installed it yet, download it from this link and install it.

Step 2: Open Visual Studio

After installing Visual Studio, open it. If you have Visual Studio Community, you can either sign in or continue without signing in.

Step 3: Create a New Project

  1. Click on "Create a new project" or navigate to File > New > Project.

A Comparison Between Compdfkit & IronPDF: Figure 3 - A Comparison Between IronPDF & DinkToPdf: Figure 1

  1. Search for the Console app in the search bar and select the Console application from the search results.

A Comparison Between Compdfkit & IronPDF: Figure 4 - A Comparison Between IronPDF & DinkToPdf: Figure 2 - In the Create a new project dialog, select C# Console Application and click on Next.

  1. Choose the project template that best fits your needs. For a basic console application, you can choose "Console App (.NET Framework)."
  2. Provide the name and save location of your project. You can also set the solution name.
  3. Choose the appropriate target framework and click "Create" to generate your project.

4. Install IronPDF

Integrating IronPDF into your project can be done through various methods, each providing a seamless setup experience.

  1. To use the Visual Studio NuGet Package Manager, start by right-clicking on "Dependencies" in your solution and selecting "Manage NuGet Packages." In the "Browse" tab, search for "IronPDF" and install the latest version for your project.

A Comparison Between Compdfkit & IronPDF: Figure 5 - Search for IronPDF using the NuGet Package Manager

  1. Alternatively, you can use the NuGet Package Manager Console. Open the console by navigating to Tools > NuGet Package Manager > Package Manager Console in Visual Studio. Once the console is open, execute the command:

    Install-Package IronPdf
    Install-Package IronPdf
    'INSTANT VB TODO TASK: The following line uses invalid syntax:
    'Install-Package IronPdf
    VB   C#

    This approach provides a quick way to install the library using a simple command line.

A Comparison Between Compdfkit & IronPDF: Figure 6 - Using the command line enter the command above

  1. For those who prefer downloading directly from the NuGet website, visit the IronPDF NuGet package page. From there, you can download the package file. After downloading, double-click the file to add it to your project, then reload your solution to complete the integration.
  2. Another method is to directly download the latest version from the IronPDF official website. This ensures you have the most up-to-date package. Follow the instructions provided on the website to manually integrate IronPDF into your Visual Studio project.

By following any of these methods, you can efficiently integrate IronPDF into your .NET project.

5. Install ComPDFKit C#

There are two main methods to add ComPDFKit to your project: using the NuGet Package Manager or a local package.

5.1 Using NuGet Package Manager

  1. Open NuGet Package Manager: In Solution Explorer, right-click on "References" and select "Manage NuGet Packages."

    1. Search and Install: Search for "ComPDFKit" in the NuGet Package Manager. Select the appropriate package (e.g., ComPDFKit.NetFramework or ComPDFKit.Conversion.NetFramework) and click "Install."

A Comparison Between Compdfkit & IronPDF: Figure 7 - Search for ComPDFKit using the NuGet Package Manager

  1. Verify Installation: Ensure the package appears under "References" in Solution Explorer.

5.2 Using a Local Package

  1. Download Package: Obtain the ComPDFKit.NetFramework.nupkg file from the official ComPDFKit website.

    1. Configure NuGet Source: Create or edit a nuget.config file in your project directory to include the path to the local package.
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <packageSources>
            <add key="ComPDFKitSource" value="path\to\directoryContainingNupkg" />
        </packageSources>
    </configuration>
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <packageSources>
            <add key="ComPDFKitSource" value="path\to\directoryContainingNupkg" />
        </packageSources>
    </configuration>
    IRON VB CONVERTER ERROR developers@ironsoftware.com
    VB   C#
  2. Install Local Package: Reopen your solution in Visual Studio, go to "Manage NuGet Packages," and select your local package source. Install the ComPDFKit package from the local source.

5.3 Apply the License Key

  1. Obtain License: Contact the ComPDFKit team to get a trial or full license.

    1. Apply the License in Code:
    bool LicenseVerify()
    {
        if (!CPDFSDKVerifier.LoadNativeLibrary())
            return false;
        LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("input your license here");
        return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
    }
    bool LicenseVerify()
    {
        if (!CPDFSDKVerifier.LoadNativeLibrary())
            return false;
        LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("input your license here");
        return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
    }
    IRON VB CONVERTER ERROR developers@ironsoftware.com
    VB   C#

    Add this method to your main application file to verify the license.

By following these steps, you can successfully integrate ComPDFKit into your C# project.

6. HTML to PDF

Converting HTML pages to PDF is a common requirement in many applications, such as generating reports, invoices, or documentation dynamically from web content. Both IronPDF and ComPDFKit offer robust solutions for this task, but their approaches and capabilities differ significantly.

The process typically starts with capturing the HTML content, which can be static or dynamically generated. The captured HTML is then processed to apply any associated stylesheets (CSS) and scripts (JavaScript), which ensures that the final PDF mirrors the original web page's appearance and behavior.

6.1. Convert HTML Pages to PDF Using IronPDF

IronPDF is a versatile library for converting HTML to PDF in C#. It uses a Chrome-based rendering engine to ensure high-quality output. This process involves rendering HTML, CSS, and JavaScript content accurately into PDF format. Here’s a basic example of how to convert an HTML string to a PDF file using IronPDF:

using IronPdf;
using System;
class Program
{
    static void Main()
    {
        // Define your HTML string
        string htmlString = @"
                <h1>Hello, IronPDF!</h1>
                <p>This is a simple PDF created from an HTML string.</p>";
        var renderer = new ChromePdfRenderer();
        // Convert the HTML string to a PDF document
        PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlString);
        // Save the PDF document to a file
        string outputPath = "sample.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
using IronPdf;
using System;
class Program
{
    static void Main()
    {
        // Define your HTML string
        string htmlString = @"
                <h1>Hello, IronPDF!</h1>
                <p>This is a simple PDF created from an HTML string.</p>";
        var renderer = new ChromePdfRenderer();
        // Convert the HTML string to a PDF document
        PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlString);
        // Save the PDF document to a file
        string outputPath = "sample.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

A Comparison Between Compdfkit & IronPDF: Figure 8 - Example out from the code above

Similarly, you can create PDFs from the HTML file. It is very helpful because sometimes HTML strings are too big and you need to add CSS with it. IronPDF helps by providing a method to directly convert HTML files along with their CSS and JS files to PDF documents.

using IronPdf;
using System;
class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        // Convert the HTML string to a PDF document
        PdfDocument pdf = renderer.RenderHtmlFileAsPdf("index.html");
        // Save the PDF document to a file
        string outputPath = "HTML File.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
using IronPdf;
using System;
class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        // Convert the HTML string to a PDF document
        PdfDocument pdf = renderer.RenderHtmlFileAsPdf("index.html");
        // Save the PDF document to a file
        string outputPath = "HTML File.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

A Comparison Between Compdfkit & IronPDF: Figure 9 - Example output from the code above utilizing IronPDF to render an HTML as a PDF

IronPDF also supports URLs to PDF and HTML files to PDF. These features are very useful in software where document management is important. IronPDF provides a wide range of features for PDF creation and manipulation, making it a powerful tool for developers.

6.2. HTML to PDF Using ComPDFKit C#

ComPDFKit does not directly support HTML to PDF conversion within its C# SDK. Instead, it offers a separate API specifically for this purpose. This API allows you to perform HTML to PDF conversions by making HTTP requests to their service.

To use the ComPDFKit HTML to PDF API, you would typically follow these steps:

  1. Send HTML Content: Create an HTTP POST request to the ComPDFKit API endpoint with your HTML content.
  2. Receive PDF Output: The API processes the HTML content and returns the generated PDF file.

Here’s an example of how you might structure such a request in C#:

using System;
using System.Net.Http;
using System.Threading.Tasks;
public class HtmlToPdfExample
{
    public static async Task ConvertHtmlToPdfAsync()
    {
        using (var client = new HttpClient())
        {
            var content = new StringContent("<h1>Hello World</h1>");
            var response = await client.PostAsync("https://api.compdfkit.com/html-to-pdf", content);
            var pdfBytes = await response.Content.ReadAsByteArrayAsync();
            System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
        }
    }
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
public class HtmlToPdfExample
{
    public static async Task ConvertHtmlToPdfAsync()
    {
        using (var client = new HttpClient())
        {
            var content = new StringContent("<h1>Hello World</h1>");
            var response = await client.PostAsync("https://api.compdfkit.com/html-to-pdf", content);
            var pdfBytes = await response.Content.ReadAsByteArrayAsync();
            System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

It's a demonstration only that we can use API like this in the C# program. There is no specific way to use it for C# in the documentation of ComPDFKit.

7. Watermark on PDF

Watermarking a PDF is an essential practice for many reasons. It helps protect the document's integrity, asserts ownership, and adds a layer of security. Watermarks can be text, logos, or images that appear either in the background or foreground of a document. They deter unauthorized use, copying, and distribution of the content. Additionally, watermarks can convey important information such as the document's status (e.g., "Confidential," "Draft," "Approved") or the identity of the creator

7.1 Watermark using IronPDF

IronPDF provides a straightforward way to add watermarks to PDF documents programmatically. This functionality is integrated into the library, allowing developers to apply watermarks using C# code.

using IronPdf;
using IronPdf.Editing;
License.LicenseKey = "License-Code";
string watermarkHtml = @"
<img style='width: 500px;' src=""C:\Users\Tayyab Ali\Desktop\watermark.png"">
<h1>IronPDF Watermark</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>");
// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
pdf.SaveAs("f://Confedential.pdf");
using IronPdf;
using IronPdf.Editing;
License.LicenseKey = "License-Code";
string watermarkHtml = @"
<img style='width: 500px;' src=""C:\Users\Tayyab Ali\Desktop\watermark.png"">
<h1>IronPDF Watermark</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>");
// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
pdf.SaveAs("f://Confedential.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

A Comparison Between Compdfkit & IronPDF: Figure 10 - Example output above from the code output showcasing the watermark added using IronPDF

In this example, the ChromePdfRenderer class is used to create a PDF from an HTML string. The ApplyWatermark method is then used to apply a watermark. The watermark consists of an image and a heading, both defined in the watermarkHtml string. The rotation parameter is set to 30 degrees, and the opacity is set to 50%, ensuring that the watermark is visible but not overpowering the main content. The resulting PDF is saved to a specified path.

7.2 Watermark using ComPDFKit

ComPDFKit provides comprehensive functionality to add watermarks to PDF documents directly within C#. This can be done programmatically by utilizing the ComPDFKit library's methods. Here’s an example of how to add a text watermark using ComPDFKit:

static private bool AddTextWatermark(CPDFDocument document)
{
    CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
    watermark.SetText("test");
    watermark.SetFontName("Helvetica"); 
    watermark.SetPages("0-3");
    byte[] color = { 255, 0, 0 };
    watermark.SetTextRGBColor(color);
    watermark.SetScale(2);
    watermark.SetRotation(0);
    watermark.SetOpacity(120);
    watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
    watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
    watermark.SetVertOffset(0);
    watermark.SetHorizOffset(0);
    watermark.SetFront(true);
    watermark.SetFullScreen(true);
    watermark.SetVerticalSpacing(10);
    watermark.SetHorizontalSpacing(10);
    watermark.CreateWatermark();
    string path = outputPath + "\\AddTextWatermarkTest.pdf";
    if (!document.WriteToFilePath(path))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + path);
    return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("SamplePDF.pdf");
if (AddTextWatermark(document))
{
    Console.WriteLine("Add text watermark done.");
}
else
{
    Console.WriteLine("Add text watermark failed.");
}
static private bool AddTextWatermark(CPDFDocument document)
{
    CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
    watermark.SetText("test");
    watermark.SetFontName("Helvetica"); 
    watermark.SetPages("0-3");
    byte[] color = { 255, 0, 0 };
    watermark.SetTextRGBColor(color);
    watermark.SetScale(2);
    watermark.SetRotation(0);
    watermark.SetOpacity(120);
    watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
    watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
    watermark.SetVertOffset(0);
    watermark.SetHorizOffset(0);
    watermark.SetFront(true);
    watermark.SetFullScreen(true);
    watermark.SetVerticalSpacing(10);
    watermark.SetHorizontalSpacing(10);
    watermark.CreateWatermark();
    string path = outputPath + "\\AddTextWatermarkTest.pdf";
    if (!document.WriteToFilePath(path))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + path);
    return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("SamplePDF.pdf");
if (AddTextWatermark(document))
{
    Console.WriteLine("Add text watermark done.");
}
else
{
    Console.WriteLine("Add text watermark failed.");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

A Comparison Between Compdfkit & IronPDF: Figure 11 - Example above from the code output showcasing the watermark added using ComPDFKit

In this example, the CPDFDocument class is used to open an existing PDF document. The AddTextWatermark method initializes a text watermark using the InitWatermark method. Various properties of the watermark are set, such as text content, font, color, scale, rotation, opacity, alignment, and spacing. The watermark is then created and applied to the specified pages of the PDF document. Finally, the modified PDF is saved to a specified path. Different methods are needed to integrate image watermarks.

8. PDFA

PDF/A is a standardized version of PDF designed for long-term digital preservation of electronic documents. Ensuring documents conform to PDF/A guarantees that they can be reliably viewed and reproduced in the future. This section explores how to create PDF/A compliant documents using two popular libraries: IronPDF and ComPDFKit.

8.1 PDFA using IronPDF

IronPDF simplifies the process of converting standard PDF documents to PDF/A-compliant ones. With IronPDF, you can easily load an existing PDF and save it in a PDF/A compliant format.

using IronPdf;
using System;
class Program
{
    static void Main()
    {
        License.LicenseKey = "License-Key";
        PdfDocument pdf = PdfDocument.FromFile("Source.pdf");
        pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3);
    }
}
using IronPdf;
using System;
class Program
{
    static void Main()
    {
        License.LicenseKey = "License-Key";
        PdfDocument pdf = PdfDocument.FromFile("Source.pdf");
        pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3);
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Here’s a brief overview of the process:

  1. Initialize IronPDF: Begin by importing the IronPDF library and setting your license key.
  2. Load the PDF: Use PdfDocument.FromFile to load your source PDF file.

  3. Convert and Save: Convert the loaded PDF to PDF/A by specifying the desired PDF/A version and saving the resulting document.

This straightforward approach makes IronPDF a convenient choice for handling PDF/A conversions.

8.2 PDFA using ComPDFKit

ComPDFKit provides a robust solution for converting PDFs to PDF/A format. The process involves initializing a PDF document, defining the output path, and invoking the conversion method.

static public bool CovertToPDFA1a(CPDFDocument document)
{
    string convertToPDFA1aPath = outputPath + "\\ConvertToPDFA1aTest.pdf";
    if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
    return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (!Directory.Exists(outputPath))
{
    Directory.CreateDirectory(outputPath);
}
if (CovertToPDFA1a(document))
{
    Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
    Console.WriteLine("Convert to PDF/A-1a failed.");
}
static public bool CovertToPDFA1a(CPDFDocument document)
{
    string convertToPDFA1aPath = outputPath + "\\ConvertToPDFA1aTest.pdf";
    if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
    return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (!Directory.Exists(outputPath))
{
    Directory.CreateDirectory(outputPath);
}
if (CovertToPDFA1a(document))
{
    Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
    Console.WriteLine("Convert to PDF/A-1a failed.");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Here’s a summary of the steps:

  1. Initialize the Document: Load the PDF document using CPDFDocument.InitWithFilePath.
  2. Setup the Output Directory: Ensure the output directory exists or create it if necessary.
  3. Convert to PDF/A: Use WritePDFAToFilePath with the specified PDF/A type to perform the conversion and save the file.

9. Digital Signature

Digital signatures are essential for verifying the authenticity and integrity of documents. This section demonstrates how to add digital signatures to PDFs using IronPDF and ComPDFKit.

9.1 Digital Signature by IronPDF

IronPDF provides a simple and effective way to apply digital signatures to PDF documents.

using IronPdf;
using IronPdf.Signing;
class Program
{
    static void Main(string[] args)
    {
        var simpleSignature = new IronPdf.Signing.PdfSignature("MyCert.p12", "newpassword");
        simpleSignature.SignPdfFile("sample.pdf");
    }
}
using IronPdf;
using IronPdf.Signing;
class Program
{
    static void Main(string[] args)
    {
        var simpleSignature = new IronPdf.Signing.PdfSignature("MyCert.p12", "newpassword");
        simpleSignature.SignPdfFile("sample.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

The process involves:

  1. Initialize IronPDF: Import the necessary IronPDF libraries.
  2. Create a Signature: Initialize a PdfSignature object with the certificate file and password.

  3. Sign the PDF: Apply the signature to the PDF using SignPdfFile.

This method ensures that your PDF documents are securely signed, enhancing their credibility and security.

9.2 Digital Signature by CompDFKit

ComPDFKit offers a comprehensive solution for creating digital signatures with extensive customization options.

private static void CreateDigitalSignature(CPDFDocument document, string certificatePath, string password)
{
    Console.WriteLine("--------------------");
    Console.WriteLine("Create digital signature.");
    CPDFSignatureCertificate certificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit");
    CPDFPage page = document.PageAtIndex(0);
    CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
    signatureField.SetRect(new CRect(28, 420, 150, 370));
    signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
    signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
    signatureField.UpdateAp();
    string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
    string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
    string reason = "I am the owner of the document.";
    string location = certificate.SubjectDict["C"];
    string DN = certificate.Subject;
    CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
    {
        Text = GetGrantorFromDictionary(certificate.SubjectDict),
        Content =
        "Name: " + name + "\n" +
        "Date: " + date + "\n" +
        "Reason: " + reason + " \n" +
        "Location: " + location + "\n" +
        "DN: " + DN + "\n",
        IsContentAlignLeft = false,
        IsDrawLogo = true,
        LogoBitmap = new Bitmap("Logo.png"),
        TextColor = new float[] { 0, 0, 0 },
        ContentColor = new float[] { 0, 0, 0 }
    };
    string filePath = outputPath + "\\" + document.FileName + "_Signed.pdf";
    signatureField.UpdataApWithSignature(signatureConfig);
    if (document.WriteSignatureToFilePath(signatureField,
        filePath,
        certificatePath, password,
        location,
        reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
    {
        Console.WriteLine("File saved in " + filePath);
        Console.WriteLine("Create digital signature done.");
    }
    else
    {
        Console.WriteLine("Create digital signature failed.");
    }
    Console.WriteLine("--------------------");
}
private static void CreateDigitalSignature(CPDFDocument document, string certificatePath, string password)
{
    Console.WriteLine("--------------------");
    Console.WriteLine("Create digital signature.");
    CPDFSignatureCertificate certificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit");
    CPDFPage page = document.PageAtIndex(0);
    CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
    signatureField.SetRect(new CRect(28, 420, 150, 370));
    signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
    signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
    signatureField.UpdateAp();
    string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
    string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
    string reason = "I am the owner of the document.";
    string location = certificate.SubjectDict["C"];
    string DN = certificate.Subject;
    CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
    {
        Text = GetGrantorFromDictionary(certificate.SubjectDict),
        Content =
        "Name: " + name + "\n" +
        "Date: " + date + "\n" +
        "Reason: " + reason + " \n" +
        "Location: " + location + "\n" +
        "DN: " + DN + "\n",
        IsContentAlignLeft = false,
        IsDrawLogo = true,
        LogoBitmap = new Bitmap("Logo.png"),
        TextColor = new float[] { 0, 0, 0 },
        ContentColor = new float[] { 0, 0, 0 }
    };
    string filePath = outputPath + "\\" + document.FileName + "_Signed.pdf";
    signatureField.UpdataApWithSignature(signatureConfig);
    if (document.WriteSignatureToFilePath(signatureField,
        filePath,
        certificatePath, password,
        location,
        reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
    {
        Console.WriteLine("File saved in " + filePath);
        Console.WriteLine("Create digital signature done.");
    }
    else
    {
        Console.WriteLine("Create digital signature failed.");
    }
    Console.WriteLine("--------------------");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

The steps include:

  1. Initialize the Document and Certificate: Load the PDF document and retrieve the certificate using CPDFPKCS12CertHelper.
  2. Create and Configure the Signature Field: Add a signature field to the PDF, set its properties, and configure the signature details.
  3. Apply the Signature: Use WriteSignatureToFilePath to apply the signature and save the signed PDF.

10. Extract Text

Extracting text from PDF documents is crucial for various data processing and analysis tasks. This section explains how to extract text from PDFs using IronPDF and ComPDFKit.

10.1 Extract Text using IronPDF

IronPDF offers a straightforward method for extracting text from PDF documents.

using IronPdf;
using System.IO;
PdfDocument pdf = PdfDocument.FromFile("PDF File With Text.pdf");
string text = pdf.ExtractAllText();
File.WriteAllText("PDF Text.txt", text);
using IronPdf;
using System.IO;
PdfDocument pdf = PdfDocument.FromFile("PDF File With Text.pdf");
string text = pdf.ExtractAllText();
File.WriteAllText("PDF Text.txt", text);
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

The process involves:

  1. Initialize IronPDF: Import the IronPDF library.
  2. Load the PDF: Use PdfDocument.FromFile to load the PDF file.

  3. Extract Text: Call ExtractAllText to retrieve all text content from the PDF.

  4. Save Text to File: Write the extracted text to a file using standard file I/O operations.

This method provides an easy and efficient way to extract and save text from PDF documents.

10.2 Extract Text using ComPDFKit

ComPDFKit provides a flexible solution for text extraction from PDF documents.

static private bool PDFToText(CPDFDocument document)
{
    string path = outputPath + "//PDFToText.txt";
    if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
    {
        return false;
    }
    Console.WriteLine("Browse the generated file in " + path);
    return true;
}
static void Main(string[] args)
{
    #region Perparation work
    Console.WriteLine("Running PDFPage test sample…\r\n");
    SDKLicenseHelper.LicenseVerify();
    CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
    if (!Directory.Exists(outputPath))
    {
        Directory.CreateDirectory(outputPath);
    }
    #endregion
    if (PDFToText(document))
    {
        Console.WriteLine("PDF to text done.");
    }
    else
    {
        Console.WriteLine("PDF to text failed.");
    }
    Console.WriteLine("--------------------");
    Console.WriteLine("Done!");
    Console.WriteLine("--------------------");
    Console.ReadLine();
}
static private bool PDFToText(CPDFDocument document)
{
    string path = outputPath + "//PDFToText.txt";
    if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
    {
        return false;
    }
    Console.WriteLine("Browse the generated file in " + path);
    return true;
}
static void Main(string[] args)
{
    #region Perparation work
    Console.WriteLine("Running PDFPage test sample…\r\n");
    SDKLicenseHelper.LicenseVerify();
    CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
    if (!Directory.Exists(outputPath))
    {
        Directory.CreateDirectory(outputPath);
    }
    #endregion
    if (PDFToText(document))
    {
        Console.WriteLine("PDF to text done.");
    }
    else
    {
        Console.WriteLine("PDF to text failed.");
    }
    Console.WriteLine("--------------------");
    Console.WriteLine("Done!");
    Console.WriteLine("--------------------");
    Console.ReadLine();
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

The steps are:

  1. Initialize the Document: Load the PDF document using CPDFDocument.InitWithFilePath.
  2. Setup the Output Directory: Ensure the output directory exists or create it if necessary.
  3. Extract and Save Text: Use PdfToText to extract text from the specified page range and save it to a file.

8. Licensing

The licensing models for IronPDF and ComPDFKit differ in their approach and usage terms. Understanding these differences can help you choose the right tool for your project's needs and budget.

9.1 IronPDF Licensing

A Comparison Between Compdfkit & IronPDF: Figure 12 - IronPDF licensing page

IronPDF operates under a commercial licensing model, meaning that for commercial or business-related applications, purchasing a license is generally required. This model offers flexibility, including options like royalty-free distribution. This allows developers to incorporate the library into their projects without facing additional costs during runtime.

IronPDF offers perpetual licenses. Perpetual licenses require a one-time payment for lifetime use, with optional fees for updates and technical support beyond the initial period. This commercial model ensures that enterprises receive dedicated support, comprehensive documentation, and access to advanced features necessary for professional PDF generation and manipulation.

9.2 ComPDFKit Licenseing

ComPDFKit employs a flexible licensing model that caters to different business needs. It offers both perpetual and subscription licenses. A perpetual license involves a one-time payment that grants lifetime access to the SDK, with optional fees for updates and extended support. Subscription licenses require regular payments (monthly or annually) and include ongoing access to updates and support.

When deciding between IronPDF and ComPDFKit, consider the specific requirements of your project, such as the need for dedicated support, budget constraints, and the scale of deployment. IronPDF's commercial model is more suitable for businesses looking for robust support and advanced features.

9. Documentation and Support

9.1. IronPDF Documentation and Support

IronPDF offers comprehensive documentation and robust support options for its users. The documentation is extensive and detailed, providing clear guidance on installation, basic usage, advanced features, and troubleshooting. The official documentation is available on Read the Docs, which includes a QuickStart guide, detailed API references, and numerous code examples to help developers get started and effectively use IronPDF's features.

IronPDF also maintains an active troubleshooting guide and technical support site through its blog and example section, where users can find solutions to common issues, such as rendering delays and deployment challenges. The support site includes a collection of articles addressing frequently asked questions and specific technical issues.

For direct support, IronPDF offers a responsive customer service team that can be contacted for more complex issues or personalized assistance. This combination of extensive documentation and strong support infrastructure makes IronPDF a reliable choice for developers looking to integrate PDF functionalities into their applications.

9.2. ComPDFKit Documentation and Support

ComPDFKit also provides thorough documentation and support resources for its users. It covers various aspects of using the SDK, from basic setup to advanced functionalities like watermarking and digital signatures. For support, ComPDFKit provides technical assistance through its customer service channels. The support team is available to help resolve technical issues, answer questions, and provide guidance on using the SDK effectively.

While both IronPDF and ComPDFKit offer strong documentation and support, IronPDF has an edge with its more extensive troubleshooting guides and a highly responsive support team. This makes it particularly advantageous for developers who might encounter complex technical challenges and need reliable assistance.

10. Conclusion

The comparison between IronPDF and ComPDFKit highlights the strengths and considerations for developers seeking robust C# libraries for PDF generation and manipulation.

ComPDFKit is a comprehensive PDF SDK that supports a wide range of functionalities necessary for handling PDF documents programmatically. It excels in PDF annotations and has extensive editing capabilities. Its features like format conversion and security options add significant value for developers.

IronPDF, on the other hand, is known for its powerful and user-friendly API. It simplifies PDF generation by rendering PDFs from HTML, CSS, and JavaScript. IronPDF excels in HTML to PDF conversion, offering seamless integration with .NET applications. The library provides extensive editing capabilities, including adding headers, footers, watermarks, and digital signatures.

IronPDF's security features ensure that sensitive information within PDF documents is well-protected. Its support for multiple .NET platforms and optimized performance for high workloads make it an ideal choice for enterprise-level applications. The commercial licensing model of IronPDF ensures dedicated support, comprehensive documentation, and access to advanced features, making it particularly suitable for professional-grade projects.

IronPDF stands out as a strong option compared to ComPDFKit for developers looking for a comprehensive and feature-rich PDF library. Its advanced functionalities, user-friendly API, and robust support infrastructure make it a preferred solution for enterprises and projects with diverse and demanding PDF-related requirements. IronPDF's extensive capabilities and dedicated support provide a significant edge, ensuring reliable and efficient PDF generation and manipulation for professional applications.

In summary, both IronPDF and ComPDFKit are powerful tools for PDF processing in C#. However, IronPDF's extensive feature set, optimized performance, and superior support make it the preferred choice for developers aiming for professional and enterprise-level applications.

IronPDF provides a free trial license for users to try out the library and its capabilities. IronPDF license starts from $749. Additionally, Iron Software bundles nine libraries for the cost of two, which includes IronXL and IronOCR along with IronPDF.

< PREVIOUS
A Comparison Between CraftMyPDF & IronPDF
NEXT >
A Comparsion Between Report .NET & IronPDF

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 10,912,787 View Licenses >