Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
With improving technology and the rise in internet usage, data is mostly sent and received in digital form, mainly in PDF files.
Working with PDF documents in C# has been difficult for developers in the recent past. There are many scenarios in which developers need to incorporate PDF viewing and PDF generation capabilities in their applications. Keeping this in mind, many libraries have been developed to facilitate these and similar tasks.
This article is going to compare two of the most popular PDF libraries for .NET and .NET Core developers. These two libraries are:
IronPDF and PDFium.NET can create, manipulate, and print PDFs in .NET applications. The question that arises is: which library should be used? Going through this article will allow you to decide for yourself.
First, let's take a look at what the two libraries have to offer, and then we will move on to the comparison itself.
PDFium.NET is used to create, modify, and view files as PDFs (portable document formats). It provides a high-level C#/VB.NET API for dynamic PDF creation on a web server and to implement Save as PDF feature in existing Desktop or Web applications.
Standout Features of PDFium.NET are:
The IronPDF .NET PDF library is tailor-made for developers, particularly for C# developers. With this amazing PDF library, you can easily incorporate PDF Viewing capabilities in your .NET projects.
IronPDF has a built-in Chromium Engine which can convert HTML to PDF very easily. This does not require any complicated, low-level APIs for manipulating PDF files. It can handle HTML source files like HTML documents, JavaScript files, and ASPX web pages.
IronPDF can customize PDFs with custom headers and footers, watermarks, and much more. It also makes reading PDF text and extracting graphics a piece of cake for developers.
Standout Features of IronPDF for .NET include:
IronPDF library is available for almost all operating systems and frameworks compatible with C#, including the following:
The rest of the article goes as follows:
There are different ways to download and install the IronPDF library. The easiest methods are as follows:
In your Visual Studio project, from the "Tools" Menu or right-click your project in the Solution Explorer and select "Manage NuGet Packages". Both these options are shown below in the screenshots.
Once the NuGet Package Manager is opened, browse for the IronPDF package and install it, as shown in the screenshot below.
IronPDF can also be downloaded through the Developer Command Prompt. Follow the steps below:
Install-Package IronPdf
IronPDF can also be directly downloaded by visiting the NuGet IronPDF Package. The steps are:
You can also download the IronPDF.DLL file directly from IronPDF's package page.
Reference the IronPDF library in your project by using the following steps:
All done! IronPDF is downloaded and installed. We will now work on installing the PDFium.NET SDK library.
We can install PDFium.NET using the NuGet Package Manager or by downloading the PDFium Windows Installer.
You can also use Package Manager Console to install. Follow the "Use Developer Command Prompt" step as mentioned in IronPDF and type the following command:
PM> Install-Package Pdfium.Net.SDK
IronPDF provides multiple methods for generating PDF files. Let's have a look at two important ones.
IronPDF makes it very simple to convert HTML to PDF with IronPDF's URL rendering using existing URLs.
Consider the following source code.
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
Dim Renderer As New IronPdf.ChromePdfRenderer()
Dim Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
Pdf.SaveAs("url.pdf")
The following code snippet shows how an HTML string can be used to render a PDF page. You can use simple HTML, or combine it with CSS, images, and JavaScript.
var Renderer = new IronPDF.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
PDF.SaveAs("pixel-perfect.pdf");
// Load external html assets: images, css and javascript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo_square.png'>", @"e:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
var Renderer = new IronPDF.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
PDF.SaveAs("pixel-perfect.pdf");
// Load external html assets: images, css and javascript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo_square.png'>", @"e:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
Dim Renderer = New IronPDF.ChromePdfRenderer()
Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>")
PDF.SaveAs("pixel-perfect.pdf")
' 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 AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo_square.png'>", "e:\site\assets\")
AdvancedPDF.SaveAs("html-with-assets.pdf")
The output is as follows:
It can generate PDF on the fly using images and text objects. However, it is unable to convert a URL or HTML string to a PDF file.
The code for generating PDFs using building PDFium.NET goes as follows:
public void CreatePDF()
{
// Step 1: Initialize PDF library and create empty document
// Return value: PdfDocument main class
PdfCommon.Initialize();
var doc = PdfDocument.CreateNew(); // Create a PDF document
// Step 2: Add new page
// Arguments: page width: 8.27", page height: 11.69", Unit of measure: inches
// The PDF unit of measure is point. There are 72 points in one inch.
var page = doc.Pages.InsertPageAt(doc.Pages.Count, 8.27f * 72, 11.69f * 72);
// Step 3: Add graphics and text contents to the page
// Insert image from file using standard System.Drawing.Bitmap class
using (PdfBitmap logo = PdfBitmap.FromFile(@"e:\site\assets\logo_square.png"))
{
PdfImageObject imageObject = PdfImageObject.Create(doc, logo, 0, 0);
//image resolution is 300 DPI and location is 1.69 x 10.0 inches.
imageObject.Matrix = new FS_MATRIX(logo.Width * 72 / 300, 0, 0, logo.Height * 72 / 300, 1.69 * 72, 10.0 * 72);
page.PageObjects.Add(imageObject);
}
// Create fonts used for text objects
PdfFont calibryBold = PdfFont.CreateFont(doc, "CalibriBold");
// Insert text objects at 7.69"; 11.02" and font size is 25
PdfTextObject textObject = PdfTextObject.Create("Sample text", 7.69f * 72, 11.02f * 72, calibryBold, 25);
textObject.FillColor = FS_COLOR.Black;
page.PageObjects.Add(textObject);
// Step 5: Generate page content and save PDF file
// argument: PDF file name
page.GenerateContent();
doc.Save(@"e:\site\sample_document.pdf", SaveFlags.NoIncremental);
}
public void CreatePDF()
{
// Step 1: Initialize PDF library and create empty document
// Return value: PdfDocument main class
PdfCommon.Initialize();
var doc = PdfDocument.CreateNew(); // Create a PDF document
// Step 2: Add new page
// Arguments: page width: 8.27", page height: 11.69", Unit of measure: inches
// The PDF unit of measure is point. There are 72 points in one inch.
var page = doc.Pages.InsertPageAt(doc.Pages.Count, 8.27f * 72, 11.69f * 72);
// Step 3: Add graphics and text contents to the page
// Insert image from file using standard System.Drawing.Bitmap class
using (PdfBitmap logo = PdfBitmap.FromFile(@"e:\site\assets\logo_square.png"))
{
PdfImageObject imageObject = PdfImageObject.Create(doc, logo, 0, 0);
//image resolution is 300 DPI and location is 1.69 x 10.0 inches.
imageObject.Matrix = new FS_MATRIX(logo.Width * 72 / 300, 0, 0, logo.Height * 72 / 300, 1.69 * 72, 10.0 * 72);
page.PageObjects.Add(imageObject);
}
// Create fonts used for text objects
PdfFont calibryBold = PdfFont.CreateFont(doc, "CalibriBold");
// Insert text objects at 7.69"; 11.02" and font size is 25
PdfTextObject textObject = PdfTextObject.Create("Sample text", 7.69f * 72, 11.02f * 72, calibryBold, 25);
textObject.FillColor = FS_COLOR.Black;
page.PageObjects.Add(textObject);
// Step 5: Generate page content and save PDF file
// argument: PDF file name
page.GenerateContent();
doc.Save(@"e:\site\sample_document.pdf", SaveFlags.NoIncremental);
}
Public Sub CreatePDF()
' Step 1: Initialize PDF library and create empty document
' Return value: PdfDocument main class
PdfCommon.Initialize()
Dim doc = PdfDocument.CreateNew() ' Create a PDF document
' Step 2: Add new page
' Arguments: page width: 8.27", page height: 11.69", Unit of measure: inches
' The PDF unit of measure is point. There are 72 points in one inch.
Dim page = doc.Pages.InsertPageAt(doc.Pages.Count, 8.27F * 72, 11.69F * 72)
' Step 3: Add graphics and text contents to the page
' Insert image from file using standard System.Drawing.Bitmap class
Using logo As PdfBitmap = PdfBitmap.FromFile("e:\site\assets\logo_square.png")
Dim imageObject As PdfImageObject = PdfImageObject.Create(doc, logo, 0, 0)
'image resolution is 300 DPI and location is 1.69 x 10.0 inches.
imageObject.Matrix = New FS_MATRIX(logo.Width * 72 \ 300, 0, 0, logo.Height * 72 \ 300, 1.69 * 72, 10.0 * 72)
page.PageObjects.Add(imageObject)
End Using
' Create fonts used for text objects
Dim calibryBold As PdfFont = PdfFont.CreateFont(doc, "CalibriBold")
' Insert text objects at 7.69"; 11.02" and font size is 25
Dim textObject As PdfTextObject = PdfTextObject.Create("Sample text", 7.69F * 72, 11.02F * 72, calibryBold, 25)
textObject.FillColor = FS_COLOR.Black
page.PageObjects.Add(textObject)
' Step 5: Generate page content and save PDF file
' argument: PDF file name
page.GenerateContent()
doc.Save("e:\site\sample_document.pdf", SaveFlags.NoIncremental)
End Sub
The output is as follows:
If we compare the output of IronPDF and PDFium project, we can clearly see that IronPDF class library-based output gives a better result using HTML rendering and without even scaling the image size. On the other hand, PDFium.NET gives a similar output to IronPDF but only with scaling the Image. If we skip this line from the code:
imageObject.Matrix = new FS_MATRIX(logo.Width * 72 / 300, 0, 0, logo.Height * 72 / 300, 1.69 * 72, 10.0 * 72);
imageObject.Matrix = new FS_MATRIX(logo.Width * 72 / 300, 0, 0, logo.Height * 72 / 300, 1.69 * 72, 10.0 * 72);
imageObject.Matrix = New FS_MATRIX(logo.Width * 72 \ 300, 0, 0, logo.Height * 72 \ 300, 1.69 * 72, 10.0 * 72)
The output will be:
Merging two or more PDFs is easy in IronPDF. Using the Merge method, you can combine two or more PDFs where each file is separated by a comma. The code goes as follows:
using IronPdf;
var html_a = @"<p> [PDF_A] </p>
<p> [PDF_A] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_A] 2nd Page</p>";
var html_b = @"<p> [PDF_B] </p>
<p> [PDF_B] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_B] 2nd Page</p>";
var Renderer = new IronPDF.ChromePdfRenderer();
var pdfdoc_a = Renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = Renderer.RenderHtmlAsPdf(html_b);
var merged = IronPDF.PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs("Merged.PDF");
using IronPdf;
var html_a = @"<p> [PDF_A] </p>
<p> [PDF_A] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_A] 2nd Page</p>";
var html_b = @"<p> [PDF_B] </p>
<p> [PDF_B] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_B] 2nd Page</p>";
var Renderer = new IronPDF.ChromePdfRenderer();
var pdfdoc_a = Renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = Renderer.RenderHtmlAsPdf(html_b);
var merged = IronPDF.PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs("Merged.PDF");
Imports IronPdf
Private html_a = "<p> [PDF_A] </p>
<p> [PDF_A] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_A] 2nd Page</p>"
Private html_b = "<p> [PDF_B] </p>
<p> [PDF_B] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_B] 2nd Page</p>"
Private Renderer = New IronPDF.ChromePdfRenderer()
Private pdfdoc_a = Renderer.RenderHtmlAsPdf(html_a)
Private pdfdoc_b = Renderer.RenderHtmlAsPdf(html_b)
Private merged = IronPDF.PdfDocument.Merge(pdfdoc_a, pdfdoc_b)
merged.SaveAs("Merged.PDF")
Using PDFium.NET, you can not only merge multiple PDF files into a single file, but also you can select certain specific pages from the source files and combine them in one PDF document.
The code below shows how it can be done using the ImportPages
method.
public void MergePDF()
{
//Initialize the SDK library.
PdfCommon.Initialize();
//Open and load a PDF document in which other files will be merged
using (var mainDoc = PdfDocument.Load(@"c:\test001.pdf")) // C# Read source PDF File #1
{
//Open one PDF document.
using (var doc = PdfDocument.Load(@"c:\doc1.pdf")) //Read PDF File #2
{
//Import all pages from document
mainDoc.Pages.ImportPages(
doc,
string.Format("1-{0}", doc.Pages.Count),
mainDoc.Pages.Count
);
}
//Open another PDF document.
using (var doc = PdfDocument.Load(@"c:\doc2.pdf"))
{
//Import all pages from document
mainDoc.Pages.ImportPages(
doc,
string.Format("1-{0}", doc.Pages.Count),
mainDoc.Pages.Count
);
}
mainDoc.Save(@"c:\ResultDocument.pdf", SaveFlags.NoIncremental);
}
}
public void MergePDF()
{
//Initialize the SDK library.
PdfCommon.Initialize();
//Open and load a PDF document in which other files will be merged
using (var mainDoc = PdfDocument.Load(@"c:\test001.pdf")) // C# Read source PDF File #1
{
//Open one PDF document.
using (var doc = PdfDocument.Load(@"c:\doc1.pdf")) //Read PDF File #2
{
//Import all pages from document
mainDoc.Pages.ImportPages(
doc,
string.Format("1-{0}", doc.Pages.Count),
mainDoc.Pages.Count
);
}
//Open another PDF document.
using (var doc = PdfDocument.Load(@"c:\doc2.pdf"))
{
//Import all pages from document
mainDoc.Pages.ImportPages(
doc,
string.Format("1-{0}", doc.Pages.Count),
mainDoc.Pages.Count
);
}
mainDoc.Save(@"c:\ResultDocument.pdf", SaveFlags.NoIncremental);
}
}
Public Sub MergePDF()
'Initialize the SDK library.
PdfCommon.Initialize()
'Open and load a PDF document in which other files will be merged
Using mainDoc = PdfDocument.Load("c:\test001.pdf") ' C# Read source PDF File #1
'Open one PDF document.
Using doc = PdfDocument.Load("c:\doc1.pdf") 'Read PDF File #2
'Import all pages from document
mainDoc.Pages.ImportPages(doc, String.Format("1-{0}", doc.Pages.Count), mainDoc.Pages.Count)
End Using
'Open another PDF document.
Using doc = PdfDocument.Load("c:\doc2.pdf")
'Import all pages from document
mainDoc.Pages.ImportPages(doc, String.Format("1-{0}", doc.Pages.Count), mainDoc.Pages.Count)
End Using
mainDoc.Save("c:\ResultDocument.pdf", SaveFlags.NoIncremental)
End Using
End Sub
One of the most important features nowadays is signing a PDF document digitally. IronPDF provides this facility. The code goes as follows:
using IronPdf;
// Cryptographically sign an existing PDF in 1 line of code!
new IronPDF.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");
/***** Advanced example for more control *****/
// Step 1. Create a PDF
var Renderer = new IronPdf.ChromePdfRenderer();
var doc = Renderer.RenderHtmlAsPDF("<h1>Testing 2048 bit digital security</h1>");
// Step 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
var signature = new IronPDF.Signing.PdfSignature("Iron.pfx", "123456");
// Step 3. Handwritten signature graphic
signature.LoadSignatureImageFromFile("handwriting.png");
//Step 4. Sign the PDF with the PDFSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(signature);
//Step 4. The PDF is not signed until saved to file, stream or byte array.
doc.SaveAs("signed.pdf");
using IronPdf;
// Cryptographically sign an existing PDF in 1 line of code!
new IronPDF.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");
/***** Advanced example for more control *****/
// Step 1. Create a PDF
var Renderer = new IronPdf.ChromePdfRenderer();
var doc = Renderer.RenderHtmlAsPDF("<h1>Testing 2048 bit digital security</h1>");
// Step 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
var signature = new IronPDF.Signing.PdfSignature("Iron.pfx", "123456");
// Step 3. Handwritten signature graphic
signature.LoadSignatureImageFromFile("handwriting.png");
//Step 4. Sign the PDF with the PDFSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(signature);
//Step 4. The PDF is not signed until saved to file, stream or byte array.
doc.SaveAs("signed.pdf");
Imports IronPdf
' Cryptographically sign an existing PDF in 1 line of code!
Call (New IronPDF.Signing.PdfSignature("Iron.p12", "123456")).SignPdfFile("any.pdf")
'''*** Advanced example for more control ****
' Step 1. Create a PDF
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim doc = Renderer.RenderHtmlAsPDF("<h1>Testing 2048 bit digital security</h1>")
' Step 2. Create a Signature.
' You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
Dim signature = New IronPDF.Signing.PdfSignature("Iron.pfx", "123456")
' Step 3. Handwritten signature graphic
signature.LoadSignatureImageFromFile("handwriting.png")
'Step 4. Sign the PDF with the PDFSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(signature)
'Step 4. The PDF is not signed until saved to file, stream or byte array.
doc.SaveAs("signed.pdf")
PDFium.NET lacks this ability to digitally sign PDF documents.
IronPDF is free to use for developing simple applications and can be licensed for commercial use at any time. It provides single project licenses, single developer licenses, agencies and multinational organizations licenses. It also provides SaaS and OEM redistribution licenses and support.
All IronPDF licenses are available with a 30-day money-back guarantee, plus a year of software support and upgrades. Most importantly, it is a perpetual license (one-time purchase). The Lite package is available. There are absolutely no recurring fees with IronPDF products. More detailed information about the available licenses is on the IronPDF Licensing page.
PDFium.NET provides a perpetual license. You can use this supported SDK version with your registration key forever. However, the key only works with some specific SDK versions that depend on the date of license purchase or renewal. You can install any new product version for free, provided that it was released before or within one year of your purchase. PDFium.NET also provides 3 different license packages:
You can visit the PDFium.NET Purchase page for complete pricing details.
The IronPDF library is an easy-to-use library for creating PDF documents without any complicated APIs. The built-in chromium engine allows pixel-perfect HTML to PDF conversion with open standard document types such as HTML, JS, CSS, JPG, PNG, GIF, and SVG.
PDFium.NET SDK is a .NET class library designed to fulfill most common needs a developer has for a more than affordable price. With PDFium.NET SDK, your apps can display and manipulate PDF documents like a charm. Its special Page object editing API is what makes this library particularly powerful.
PDFium.NET licenses come in three editions as mentioned above. The single project license provides facilities for single developer and up to three developers starting from $720 and $900 respectively. This is somewhat cheaper than IronPDF, which has a lite version starting at a lower price.
IronPDF offers an unlimited license at a competitive price. In contrast, PDFium.NET has an organizational license for an unlimited number of developers for a premium price. On the contrary, IronPDF provides a professional license that can be used by 10 developers, and is about half of PDFium.NET's equivalent license for 10 developers.
In the examples above, you have seen IronPDF create and modify PDF documents using much fewer lines of code compared to PDFium.NET. This helps to ease the workload of the developer and allows them to be more productive. IronPDF provides multiple methods to convert from almost any format to PDF. In contrast, PDFium.NET only offers a few methods like images and text to PDF.
You can now purchase all of Iron Software's product libraries for just the price of two of them. Additionally, there is a free trial to test the functionality.
9 .NET API products for your office documents