Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Adobe developed the Portable Document Format to facilitate the sharing of text and image-based documents (PDF). To view a PDF image file, you must use a different application. Many businesses use PDF documents in today's culture for a variety of tasks, including the preparation of invoices and other paperwork.
Developers also use the existing PDF file format to produce documents or image file that adhere to client specifications. Fortunately, libraries that simplify the process have made producing PDFs simpler than ever. Consider factors like build, read, and convert capabilities when picking a library for your project in order to select the finest one that is readily available.
In this post, two of the most widely used Dot NET PDF libraries will be compared. They are:
In your Microsoft.NET application or project, you can create, read, and modify PDFs using either the IronPDF or iText PDF libraries. We will have a look at the capabilities of the 2 libraries first rather than shifting directly to the overall performance, fees for converting and handling the PDFs in order to determine which library is better for your application. Microsoft.NET Frameworks support both libraries. Additionally, each library's duration will be recorded for reference and later research. To know about the comparison, click here.
A Java library and system that can convert text into PDF files is called iText PDF. Text adheres to the AGPL software licensing model. The AGPL software license is free and open-source.
Developers can quickly produce, read, and change PDF files with the help of the robust IronPDF, a PDF .NET library. IronPDF has a Chrome engine at its core and offers a wealth of practical and potent capabilities, including the ability to convert HTML5, JavaScript, CSS, and picture files to PDF, add unique Headers and Footers, and produce PDFs precisely as they appear in a web browser. Various web and .NET formats, including HTML, ASPX, Razor View, and MVC, are supported by IronPDF. IronPDF's key attributes are as follows:
Find iText first by using the NuGet Package Manager. iText7 and iText.pdfhtml must both be installed because the features of these packages are divided among numerous packages.
Install the following packages as shown below if you prefer the Visual Studio Command-Line:
Install-Package itext7 && Install-Package itext7.pdfhtml
Since iText7 is the most recent version, we are using it in our solution.
As seen in the screenshot below, we can easily search for "IronPDF" in the Package Manager:
The list of relevant search results is displayed in the above graphic. To install the package on your machine, please check the necessary boxes.
If you want to install the package using command line, add the following line into the terminal tab of the package manager:
:PackageInstall
The package is now prepared for usage and will download and install in the current project.
We can create PDF documents with public static byte arrays generated from the iText document doc. Below is the sample which help us to create a new document with the help of the iText PDF library.
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using System.IO;
using iText.Kernel.Geom;
using iText.Html2pdf;
var html = "<h1>Hello world</h1>";
//byte array
byte [] result;
//create new MemoryStream using var ms
using (var ms = new MemoryStream())
{
//new document
var doc = new PdfDocument(new PdfWriter(ms));
doc.SetDefaultPageSize(PageSize.A4);
doc.SetTagged();
HtmlConverter.ConvertToPdf(html, doc, new ConverterProperties());
result = ms.ToArray();
}
File.WriteAllBytes(@"test.pdf", result);
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using System.IO;
using iText.Kernel.Geom;
using iText.Html2pdf;
var html = "<h1>Hello world</h1>";
//byte array
byte [] result;
//create new MemoryStream using var ms
using (var ms = new MemoryStream())
{
//new document
var doc = new PdfDocument(new PdfWriter(ms));
doc.SetDefaultPageSize(PageSize.A4);
doc.SetTagged();
HtmlConverter.ConvertToPdf(html, doc, new ConverterProperties());
result = ms.ToArray();
}
File.WriteAllBytes(@"test.pdf", result);
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.Layout.Element
Imports iText.Layout.Properties
Imports System.IO
Imports iText.Kernel.Geom
Imports iText.Html2pdf
Private html = "<h1>Hello world</h1>"
'byte array
Private result() As Byte
'create new MemoryStream var ms
Using ms = New MemoryStream()
'new document
Dim doc = New PdfDocument(New PdfWriter(ms))
doc.SetDefaultPageSize(PageSize.A4)
doc.SetTagged()
HtmlConverter.ConvertToPdf(html, doc, New ConverterProperties())
result = ms.ToArray()
End Using
File.WriteAllBytes("test.pdf", result)
The above example shows we are creating a PDF document from the given HTML string. First, we are creating MemoryStream
to hold the data. Then we are creating PdfWriter
and passing the MemoryStream
as a parameter to the hold the data. Then we are creating the PDF file with the help of the HtmlConverter
. After that, all the output has been saved in the MemoryStream
. Then we are converting the data into bytes, and then we are using the File class to save the MemoryStream
ms into a new file like the below output.
IronPDF makes PDF file creation very simple with few lines of code. Below is the sample code to create PDF file using IronPDF.
var html = "<h1>Hello world</h1>";
var pdf = new IronPdf.ChromePdfRenderer();
var bytedata=pdf.RenderHtmlAsPdf(html).BinaryData;
File.WriteAllBytes(@"test.pdf", bytedata);
var html = "<h1>Hello world</h1>";
var pdf = new IronPdf.ChromePdfRenderer();
var bytedata=pdf.RenderHtmlAsPdf(html).BinaryData;
File.WriteAllBytes(@"test.pdf", bytedata);
Dim html = "<h1>Hello world</h1>"
Dim pdf = New IronPdf.ChromePdfRenderer()
Dim bytedata=pdf.RenderHtmlAsPdf(html).BinaryData
File.WriteAllBytes("test.pdf", bytedata)
In the first step, we are creating an object for ChromePdfRenderer
which helps to create PDF file. Then we are adding the HTML data into the PDF document using the method RenderHtmlAsPdf
. Then we are converting the data into byte array. Last step is using the File which helps us to convert byte array to PDF file. The output will be like below.
For more code tutorials, click here.
iText7 is one of the commonly used PDF libraries. iText code is so complex, and it is not suitable for beginners. We need a basic knowledge about the library to use this on user application. iText is generating PDF files with large space thus it may impact the user memory when they generate file with many pages. iText7 has divided the library into multiple packages unlike other packages. iText7 is having dependency with multiple packages. We need to download all the packages to make it work, it may increase the size of the application. Both a development license and a business license is free with iText. Click here to read more about the iText license.
On the other hand, IronPDF is easy and simple to use. With the few lines of code we are able to create PDF files. It is suitable for beginners and no basic knowledge is needed to use this application. IronPDF does not have any dependency with any other package. It is solo package that works all alone. Developers can choose from a variety of licenses to buy to suit their needs in addition to a free license that is provided. The $749 Lite edition does include all library features, such as a permanent license, a 30-day money-back guarantee, a year of software support, upgrades, and possibilities for SaaS and OEM redistribution. Additionally, it excludes recurring expenses. These licenses are one-time purchases that can be applied to development, staging, and production. Additionally, time-limited, non-distributable free licenses are available from IronPDF. Please click here for a detailed breakdown of IronPDF prices and licensing information.
9 .NET API products for your office documents