Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Looking for the perfect PDF tools for the .NET Framework?
In this article, we will take a look at how to work with PDF files in C# (one of the most popular programming languages). We will discuss two industry-leading PDF tools for C# on the .NET Framework, using code samples to compare them based on their performance and features. In the end, we will examine their licensing details and learn how to obtain license keys.
The two PDF libraries are:
IronPDF is a C# .NET library developed by Iron Software to solve all PDF problems for C# .NET developers using a single library. IronPDF is powered by a chromium engine and has a variety of helpful and powerful capabilities such as the conversion of HTML5, JavaScript, CSS, and image files to PDF, creating custom headers and footers, and displaying PDFs precisely as they appear in a browser. IronPDF allows you to read data from PDF files and insert it into your .NET applications and data storage systems automatically. You can import, move, and index content from old PDF document storage into your document management and business applications.
This functionality allows you to generate PDF files from various formats such as HTML, MVC views, Web Forms, HTML Strings, and URLs.
In many circumstances, you can easily extract embedded text from PDFs. However, if that fails, your text is most likely embedded in an image. To scan documents for visual text, rather than plain text, use the IronOCR library.
Headers and footers can be added while creating a PDF or to existing PDFs. Using the Print Options property, you may create a header and footer for each document page. These parameters are available on the ChromePdfRenderer object. This example runs within a .NET Core console app.
This enables users to generate photos from PDFs as well as PDFs from photographs. It supports image extraction, various image extensions, and PDF printing.
IronPDF also includes 128-bit PDF encryption, password-protected PDF locking, and the digital signing of PDFs.
IronPDF tool allows you to add watermarks, add pages, remove pages, backgrounds, foregrounds, and much more to your PDFs.
IronPDF supports almost all operating systems and frameworks compatible with C#, such as:
PDFNet .NET SDK by PDFTron brings precise PDF processing, annotation, editing, and creation to any framework or application on the web, mobile, desktop, or server. It manages the entire document and information management process with your infrastructure and eliminates the need for third-party server dependencies. PDFTron's web platform comes with a JS version with the supported platform and a demo license key for all the PDF SDKs.
One of the most significant benefits of PDFNet is that it is genuinely cross-platform, allowing our users to simply add PDF compatibility and relevant business functionality to their workflows and apps across many distinct mobile and desktop contexts, all while using virtually the same interface.
The PDFNet SDK is compatible with many platforms and frameworks. To ensure platform consistency, the JavaScript API is utilized in the same way as the PDFNet API. Node.js and Electron versions of the SDK are also available. This package requires unmanaged add-on binaries.
Brings safe, scalable, and high-fidelity reading and editing abilities for PDFs to users across online, mobile, and desktop platforms.
Create customized signing procedures. Digitally signed papers can be certified, validated, and sealed.
Remove sensitive data from documents, such as personal information or personal health information, while leaving the document searchable.
Pages can be added, removed, or rearranged. Documents may be assembled, merged, or divided into parts. View several documents simultaneously in the same reader or beside each other.
In this article, we are going to use a console application to generate PDF documents.
Open the Visual Studio software and go to the File menu. Select "new project" and then select console application.
Enter the project name and select the path in the appropriate text box. Then, click the create button. Select the required .NET framework, as in the screenshot below:
The Visual Studio project will now generate the structure for the console application. Once finished, it will open the program.cs
file, in which you can write and execute source code.
Now we can add the library and test the program.
The IronPDF library can be downloaded and installed in four different ways. These are:
The Visual Studio software provides the NuGet Package Manager option to install the package directly to the solution. The below screenshot shows how to open the NuGet Package Manager.
With the Package Manager GUI open, click on the Browse tab and search for "IronPDF:"
In the above image, we can see the list of related packages from the search. Select the IronPDF option and install the package to our solution.
Install-Package IronPdf
The IronPDF package will now be installed in the project.
The third way is to download the NuGet package directly from the NuGet Gallery IronPDF Package.
Download the latest package directly from the IronPDF Download Page. After the download, follow the steps below to add the package to the project.
The PDFNet SDK can be downloaded and installed in four different ways.
As explained above, go to tools in Visual Studio and open the NuGet package manager. A list will appear — click on manage NuGet package for solutions.
A window will appear with a search bar. Search for PDFNet and install it in the project.
Install-Package PDFNet ---Version 9.2.0
The third way is to download the NuGet package directly from the NuGet Gallery PDFNet Package.
You can also install the PDFNet API using the PDFNetLoader.dll file. Download it from GitHub Releases for PDFNetLoader.dll.
Download the package, place it in the bin file of the project, and run it. In your Visual Studio project, add PDFNetLoader.dll as a reference.
Printing a PDF file is a must-have feature for modern applications that deal with PDFs. Here, we will discuss how to print PDF files using both tools.
IronPDF prints a PDF by sending it to the computer's default printer. This will open the Windows print interface — just click print to make it happen.
using IronPdf;
// Create a new PDF and print it
var Renderer = new IronPdf.ChromePdfRenderer();
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Send the PDF to the default printer to print
Pdf.Print(300, false);
using IronPdf;
// Create a new PDF and print it
var Renderer = new IronPdf.ChromePdfRenderer();
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Send the PDF to the default printer to print
Pdf.Print(300, false);
Imports IronPdf
' Create a new PDF and print it
Private Renderer = New IronPdf.ChromePdfRenderer()
Private Pdf As PdfDocument = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
' Send the PDF to the default printer to print
Pdf.Print(300, False)
PDFTron's PDFNet SDK also provides a printing feature. Below is the source code snippet for printing a PDF file in PDFNet.
using System;
using System.Drawing;
using System.Drawing.Printing;
using pdftron;
using pdftron.PDF;
using pdftron.Common;
using pdftron.Filters;
namespace PDFPrintTestCS
{
Console.WriteLine("Opening the input file...");
using (pdfdoc = new PDFDoc(input_path + "tiger.pdf"))
{
pdfdoc.InitSecurityHandler();
Console.WriteLine("Printing the input file using PDF.Print.StartPrintJob...");
PrinterMode printerMode = new PrinterMode();
printerMode.SetAutoCenter(true);
printerMode.SetAutoRotate(true);
printerMode.SetCollation(true);
printerMode.SetCopyCount(1);
printerMode.SetDPI(300); // regardless of ordering, an explicit DPI setting overrides the OutputQuality setting
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_Auto);
printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1, PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom);
printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations);
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale);
printerMode.SetOutputPageBorder(false);
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium);
printerMode.SetPaperSize(new Rect(0, 0, 612, 792));
PageSet pagesToPrint = new PageSet(1, pdfdoc.GetPageCount(), PageSet.Filter.e_all);
Print.StartPrintJob(pdfdoc, "", pdfdoc.GetFileName(), "", pagesToPrint, printerMode, null);
}
}
using System;
using System.Drawing;
using System.Drawing.Printing;
using pdftron;
using pdftron.PDF;
using pdftron.Common;
using pdftron.Filters;
namespace PDFPrintTestCS
{
Console.WriteLine("Opening the input file...");
using (pdfdoc = new PDFDoc(input_path + "tiger.pdf"))
{
pdfdoc.InitSecurityHandler();
Console.WriteLine("Printing the input file using PDF.Print.StartPrintJob...");
PrinterMode printerMode = new PrinterMode();
printerMode.SetAutoCenter(true);
printerMode.SetAutoRotate(true);
printerMode.SetCollation(true);
printerMode.SetCopyCount(1);
printerMode.SetDPI(300); // regardless of ordering, an explicit DPI setting overrides the OutputQuality setting
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_Auto);
printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1, PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom);
printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations);
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale);
printerMode.SetOutputPageBorder(false);
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium);
printerMode.SetPaperSize(new Rect(0, 0, 612, 792));
PageSet pagesToPrint = new PageSet(1, pdfdoc.GetPageCount(), PageSet.Filter.e_all);
Print.StartPrintJob(pdfdoc, "", pdfdoc.GetFileName(), "", pagesToPrint, printerMode, null);
}
}
Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports pdftron
Imports pdftron.PDF
Imports pdftron.Common
Imports pdftron.Filters
Namespace PDFPrintTestCS
Console.WriteLine("Opening the input file...")
pdfdoc = New PDFDoc(input_path & "tiger.pdf")
Using pdfdoc
pdfdoc.InitSecurityHandler()
Console.WriteLine("Printing the input file using PDF.Print.StartPrintJob...")
Dim printerMode As New PrinterMode()
printerMode.SetAutoCenter(True)
printerMode.SetAutoRotate(True)
printerMode.SetCollation(True)
printerMode.SetCopyCount(1)
printerMode.SetDPI(300) ' regardless of ordering, an explicit DPI setting overrides the OutputQuality setting
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_Auto)
printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1, PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom)
printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait)
printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations)
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale)
printerMode.SetOutputPageBorder(False)
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium)
printerMode.SetPaperSize(New Rect(0, 0, 612, 792))
Dim pagesToPrint As New PageSet(1, pdfdoc.GetPageCount(), PageSet.Filter.e_all)
Print.StartPrintJob(pdfdoc, "", pdfdoc.GetFileName(), "", pagesToPrint, printerMode, Nothing)
End Using
End Namespace
Both libraries possess HTML to PDF conversion capabilities, but the methods are slightly different.
IronPDF does not require the use of JSON or encryption mechanisms. IronPDF supports a wide range of methods. For example:
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf");
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf");
Imports IronPdf
Private Renderer = New IronPdf.ChromePdfRenderer()
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf")
using IronPdf;
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
using IronPdf;
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
Imports IronPdf
Private Renderer As New IronPdf.ChromePdfRenderer()
Private Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
Pdf.SaveAs("url.pdf")
PDFNet also provides HTML-to-PDF conversion features using both page conversion and URL conversion. Due to the lengthy code, we will only give you one example here.
class HTML2PDFSample
{
private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
static HTML2PDFSample() {}
static void Main(string [] args)
{
string output_path = "../../../../TestFiles/Output/html2pdf_example";
string host = "https://www.pdftron.com";
string page0 = "/";
string page1 = "/support";
string page2 = "/blog";
HTML2PDF.SetModulePath("../../../../../Lib");
if (!HTML2PDF.IsModuleAvailable())
{
Console.WriteLine();
Console.WriteLine("Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.");
Console.WriteLine("-------------------------------");
Console.WriteLine("The HTML2PDF module is an optional add-on, available for download");
Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
Console.WriteLine("module, ensure that the SDK is able to find the required files");
Console.WriteLine("using the HTML2PDF.SetModulePath() function.");
Console.WriteLine();
return;
}
try
{
using (PDFDoc doc = new PDFDoc())
{
if ( HTML2PDF.Convert(doc, host + page0) )
doc.Save(output_path + "_01.pdf", SDFDoc.SaveOptions.e_linearized);
else
Console.WriteLine("Conversion failed.");
}
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}
}
}
class HTML2PDFSample
{
private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
static HTML2PDFSample() {}
static void Main(string [] args)
{
string output_path = "../../../../TestFiles/Output/html2pdf_example";
string host = "https://www.pdftron.com";
string page0 = "/";
string page1 = "/support";
string page2 = "/blog";
HTML2PDF.SetModulePath("../../../../../Lib");
if (!HTML2PDF.IsModuleAvailable())
{
Console.WriteLine();
Console.WriteLine("Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.");
Console.WriteLine("-------------------------------");
Console.WriteLine("The HTML2PDF module is an optional add-on, available for download");
Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
Console.WriteLine("module, ensure that the SDK is able to find the required files");
Console.WriteLine("using the HTML2PDF.SetModulePath() function.");
Console.WriteLine();
return;
}
try
{
using (PDFDoc doc = new PDFDoc())
{
if ( HTML2PDF.Convert(doc, host + page0) )
doc.Save(output_path + "_01.pdf", SDFDoc.SaveOptions.e_linearized);
else
Console.WriteLine("Conversion failed.");
}
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}
}
}
Friend Class HTML2PDFSample
Private Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()
Shared Sub New()
End Sub
Shared Sub Main(ByVal args() As String)
Dim output_path As String = "../../../../TestFiles/Output/html2pdf_example"
Dim host As String = "https://www.pdftron.com"
Dim page0 As String = "/"
Dim page1 As String = "/support"
Dim page2 As String = "/blog"
HTML2PDF.SetModulePath("../../../../../Lib")
If Not HTML2PDF.IsModuleAvailable() Then
Console.WriteLine()
Console.WriteLine("Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.")
Console.WriteLine("-------------------------------")
Console.WriteLine("The HTML2PDF module is an optional add-on, available for download")
Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this")
Console.WriteLine("module, ensure that the SDK is able to find the required files")
Console.WriteLine("using the HTML2PDF.SetModulePath() function.")
Console.WriteLine()
Return
End If
Try
Using doc As New PDFDoc()
If HTML2PDF.Convert(doc, host & page0) Then
doc.Save(output_path & "_01.pdf", SDFDoc.SaveOptions.e_linearized)
Else
Console.WriteLine("Conversion failed.")
End If
End Using
Catch e As PDFNetException
Console.WriteLine(e.Message)
End Try
End Sub
End Class
IronPDF is a library that offers a free developer license. IronPDF also offers a special price structure: the light package begins at $749 with no hidden costs. It is also possible to redistribute SaaS and OEM products. All licenses include a 30-day money-back guarantee, a year of software support and upgrades, development/testing/staging/production validity, and a perpetual license (one-time purchase). IronPDF licenses provide maximal performance for users' needs. Go to this IronPDF Licensing Page to see IronPDF's whole pricing structure and license.
The PDFTron PDFNet SDK comes with several license choices that are tailored to your business needs. Three types of licenses come with enterprise and OEM redistributions. Enterprise licenses are only for organization use and can not be used in app distribution. Additional APIs requiring filesystem access is also included with the licenses. All licenses come with a license key. The three types of licenses are
For further information on their license structures, visit this PDFTron Licensing Information Page.
IronPDF offers a lot of features and functionality for processing PDF files and converting them to different formats. Conversions from HTML to PDF are produced in a vector format that is appropriate for high-quality commercial printing. As a result, you'll receive a clear, high-quality PDF. License and pricing information can be found on the website.
Similar to IronPDF, PDFNet aids with the transition, annotation, signature, filling, conversion, and editing of PDF files. It supports multiple platforms, including Windows, IOS, Android, WEB, and Linux. For production use, PDFNet SDKs need a product key.
IronPDF's licenses are developer-centric, meaning that you have to get a license based on how many developers are going to use the product. On the other hand, PDFNet licenses don't work in the same manner, operating instead on a feature-based license. This means that you have to get the license that supports the features that are required. IronPDF licenses include all features out of the box. With PDFNet, some features, such as document conversion, need to be bought as add-ons.
The IronPDF library offers features in an organized manner, making it easy to write code that performs big tasks using a few lines of code. Iron Software is currently offering a five-tool package for the price of just two. The tools included in the IronSuite are:
Please visit this IronSuite Information Page to Explore IronSuite.
9 .NET API products for your office documents