Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
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.
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.
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.
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.
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.
Visual Studio is the best IDE for C# projects. If you haven't downloaded and installed it yet, download it from this Visual Studio Downloads page.
After installing Visual Studio, open it. If you have Visual Studio Community, you can either sign in or continue without signing in.
Click on "Create a new project" or navigate to File > New > Project.
Search for the Console app in the search bar and select the Console application from the search results.
Integrating IronPDF into your project can be done through various methods, each providing a seamless setup experience.
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.
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
This approach provides a quick way to install the library using a simple command line.
By following any of these methods, you can efficiently integrate IronPDF into your .NET project.
There are two main methods to add ComPDFKit to your project: using the NuGet Package Manager or a local package.
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>
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
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.
Converting HTML 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.
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}");
}
}
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main()
' Define your HTML string
Dim htmlString As String = "
<h1>Hello, IronPDF!</h1>
<p>This is a simple PDF created from an HTML string.</p>"
Dim renderer = New ChromePdfRenderer()
' Convert the HTML string to a PDF document
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlString)
' Save the PDF document to a file
Dim outputPath As String = "sample.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine($"PDF created successfully and saved to {outputPath}")
End Sub
End Class
Similarly, you can create PDFs from an 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 file 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 file 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}");
}
}
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
' Convert the HTML file to a PDF document
Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("index.html")
' Save the PDF document to a file
Dim outputPath As String = "HTML File.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine($"PDF created successfully and saved to {outputPath}")
End Sub
End Class
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.
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:
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);
}
}
}
Imports System
Imports System.Net.Http
Imports System.Threading.Tasks
Public Class HtmlToPdfExample
Public Shared Async Function ConvertHtmlToPdfAsync() As Task
Using client = New HttpClient()
Dim content = New StringContent("<h1>Hello World</h1>")
Dim response = Await client.PostAsync("https://api.compdfkit.com/html-to-pdf", content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
System.IO.File.WriteAllBytes("output.pdf", pdfBytes)
End Using
End Function
End Class
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.
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.
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;
class Program
{
static void Main()
{
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 30 degrees rotation and 50% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
pdf.SaveAs("Confidential.pdf");
}
}
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
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 30 degrees rotation and 50% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
pdf.SaveAs("Confidential.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Friend Class Program
Shared Sub Main()
License.LicenseKey = "License-Code"
Dim watermarkHtml As String = "
<img style='width: 500px;' src='C:\Users\Tayyab Ali\Desktop\watermark.png'>
<h1>IronPDF Watermark</h1>"
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>")
' Apply watermark with 30 degrees rotation and 50% opacity
pdf.ApplyWatermark(watermarkHtml, rotation:= 30, opacity:= 50)
pdf.SaveAs("Confidential.pdf")
End Sub
End Class
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.
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 = "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 = "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.");
}
Private Shared Function AddTextWatermark(ByVal document As CPDFDocument) As Boolean
Dim watermark As CPDFWatermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT)
watermark.SetText("test")
watermark.SetFontName("Helvetica")
watermark.SetPages("0-3")
Dim color() As Byte = { 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()
Dim path As String = "AddTextWatermarkTest.pdf"
If Not document.WriteToFilePath(path) Then
Return False
End If
Console.WriteLine("Browse the changed file in " & path)
Return True
End Function
Private document As CPDFDocument = CPDFDocument.InitWithFilePath("SamplePDF.pdf")
If AddTextWatermark(document) Then
Console.WriteLine("Add text watermark done.")
Else
Console.WriteLine("Add text watermark failed.")
End If
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.
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.
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);
}
}
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main()
License.LicenseKey = "License-Key"
Dim pdf As PdfDocument = PdfDocument.FromFile("Source.pdf")
pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3)
End Sub
End Class
Here’s a brief overview of the process:
This straightforward approach makes IronPDF a convenient choice for handling PDF/A conversions.
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 = "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 (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 = "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 (CovertToPDFA1a(document))
{
Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
Console.WriteLine("Convert to PDF/A-1a failed.");
}
Public Shared Function CovertToPDFA1a(ByVal document As CPDFDocument) As Boolean
Dim convertToPDFA1aPath As String = "ConvertToPDFA1aTest.pdf"
If Not document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath) Then
Return False
End If
Console.WriteLine("Browse the changed file in " & convertToPDFA1aPath)
Return True
End Function
Private document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
If CovertToPDFA1a(document) Then
Console.WriteLine("Convert to PDF/A-1a done.")
Else
Console.WriteLine("Convert to PDF/A-1a failed.")
End If
Here’s a summary of the steps:
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.
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 PdfSignature("MyCert.p12", "newpassword");
simpleSignature.SignPdfFile("sample.pdf");
}
}
using IronPdf;
using IronPdf.Signing;
class Program
{
static void Main(string[] args)
{
var simpleSignature = new PdfSignature("MyCert.p12", "newpassword");
simpleSignature.SignPdfFile("sample.pdf");
}
}
Imports IronPdf
Imports IronPdf.Signing
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim simpleSignature = New PdfSignature("MyCert.p12", "newpassword")
simpleSignature.SignPdfFile("sample.pdf")
End Sub
End Class
The process involves:
This method ensures that your PDF documents are securely signed, enhancing their credibility and security.
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 = 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 = 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("--------------------");
}
Imports Microsoft.VisualBasic
Private Shared Sub CreateDigitalSignature(ByVal document As CPDFDocument, ByVal certificatePath As String, ByVal password As String)
Console.WriteLine("--------------------")
Console.WriteLine("Create digital signature.")
Dim certificate As CPDFSignatureCertificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit")
Dim page As CPDFPage = document.PageAtIndex(0)
Dim signatureField As CPDFSignatureWidget = TryCast(page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS), 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()
Dim name As String = GetGrantorFromDictionary(certificate.SubjectDict) & vbLf
Dim [date] As String = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
Dim reason As String = "I am the owner of the document."
Dim location As String = certificate.SubjectDict("C")
Dim DN As String = certificate.Subject
Dim signatureConfig As New CPDFSignatureConfig With {
.Text = GetGrantorFromDictionary(certificate.SubjectDict),
.Content = "Name: " & name & vbLf & "Date: " & [date] & vbLf & "Reason: " & reason & " " & vbLf & "Location: " & location & vbLf & "DN: " & DN & vbLf,
.IsContentAlignLeft = False,
.IsDrawLogo = True,
.LogoBitmap = New Bitmap("Logo.png"),
.TextColor = New Single() { 0, 0, 0 },
.ContentColor = New Single() { 0, 0, 0 }
}
Dim filePath As String = document.FileName & "_Signed.pdf"
signatureField.UpdataApWithSignature(signatureConfig)
If document.WriteSignatureToFilePath(signatureField, filePath, certificatePath, password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone) Then
Console.WriteLine("File saved in " & filePath)
Console.WriteLine("Create digital signature done.")
Else
Console.WriteLine("Create digital signature failed.")
End If
Console.WriteLine("--------------------")
End Sub
The steps include:
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.
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);
Imports IronPdf
Imports System.IO
Private pdf As PdfDocument = PdfDocument.FromFile("PDF File With Text.pdf")
Private text As String = pdf.ExtractAllText()
File.WriteAllText("PDF Text.txt", text)
The process involves:
This method provides an easy and efficient way to extract and save text from PDF documents.
ComPDFKit provides a flexible solution for text extraction from PDF documents.
static private bool PDFToText(CPDFDocument document)
{
string path = "//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)
{
Console.WriteLine("Running PDFPage test sample…\r\n");
SDKLicenseHelper.LicenseVerify();
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
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 = "//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)
{
Console.WriteLine("Running PDFPage test sample…\r\n");
SDKLicenseHelper.LicenseVerify();
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
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();
}
Imports Microsoft.VisualBasic
Private Shared Function PDFToText(ByVal document As CPDFDocument) As Boolean
Dim path As String = "//PDFToText.txt"
If Not document.PdfToText("1-" & document.PageCount.ToString(), path) Then 'Page ranges are counted from 1
Return False
End If
Console.WriteLine("Browse the generated file in " & path)
Return True
End Function
Shared Sub Main(ByVal args() As String)
Console.WriteLine("Running PDFPage test sample…" & vbCrLf)
SDKLicenseHelper.LicenseVerify()
Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
If PDFToText(document) Then
Console.WriteLine("PDF to text done.")
Else
Console.WriteLine("PDF to text failed.")
End If
Console.WriteLine("--------------------")
Console.WriteLine("Done!")
Console.WriteLine("--------------------")
Console.ReadLine()
End Sub
The steps are:
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.
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.
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.
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.
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.
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 licenses start from $749. Additionally, Iron Software bundles nine libraries for the cost of two, which includes IronXL and IronOCR along with IronPDF.
PDF, or Portable Document Format, was created by Adobe to ensure uniformity in document sharing. It maintains layout, text, and images consistently across various devices and operating systems, making it ideal for distributing documents without altering the original content.
C# PDF libraries provide solutions for working with PDF files, enabling document creation, content modification, and the extraction of text and images. They support features like form handling, digital signatures, and compatibility across different platforms. IronPDF is an example of such a library, offering robust features for PDF manipulation.
ComPDFKit PDF SDK offers features such as PDF viewing, annotations, form handling, PDF editing, conversion to various formats, security features, and OCR for converting scanned documents into editable PDFs.
IronPDF excels in converting HTML, CSS, and JavaScript content into high-quality PDF documents. It supports conversion from HTML strings, URLs, ASPX webforms, and MVC views, making it a flexible solution for various web-based content.
IronPDF provides robust security options such as setting passwords and permissions, encrypting documents, and adding digital signatures, ensuring sensitive information within PDF documents is protected against unauthorized access.
IronPDF operates under a commercial licensing model, offering perpetual licenses with a one-time payment for lifetime use. ComPDFKit offers both perpetual and subscription licenses, catering to different business needs.
ComPDFKit provides methods for converting PDFs to PDF/A format for long-term digital preservation. It involves initializing a PDF document, defining the output path, and invoking the conversion method.
IronPDF offers comprehensive documentation and robust support options, including a responsive customer service team. ComPDFKit also provides thorough documentation and technical support through its customer service channels.
IronPDF's extensive feature set, optimized performance, and superior support make it the preferred choice for developers aiming for professional and enterprise-level applications, offering a robust solution for comprehensive PDF generation and manipulation.