Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
When working with PDFs in C#.NET, using PDF manipulation and generation libraries are preferrable to accomplishing our tasks from scratch. SpirePDF and IronPDF both provide the ability to create, edit and print PDF files in .NET and .NET Core. They can also read PDF text, data, table, and image examples very competently.
We will examine these two libraries in this article. We will show what each PDF library can do, and compare how they do it through code examples and step-by-step tutorials. Although this article cannot cover all features of both PDF libraries, it will explain the most common and most popular uses of each. This will allow you to decide which one is best suited to your projects.
IronPDF is the HTML-to-PDF Rendering Library for C# and Java. Convert your webpages into functional, pixel-perfect PDFs quickly and with minimal lines of code. Learn more about the capabilities of IronPDF for .NET C# in this article below. Learn more about IronPDF for Java here.
There are many times that the tools provided to us by Microsoft as part of Visual Studio are lacking functionality or usability. This is where third-party libraries come in. Developers make use of third-party libraries for their ease of use, or, mostly, for their features.
This article will compare two of the most popular PDF libraries for .NET and .NET Core developers. These two libraries are:
Spire.PDF for .NET is an API that can be applied to creating, editing, writing, reading and handling PDF files without the need for any external dependencies in C#, VB.NET, ASP.NET, .NET Core, Xamarin applications. With Spire.PDF you can create PDF files from scratch or process existing PDF documents solely through C#/VB.NET without having to install Adobe Acrobat.
IronPDF enables .NET and .NET Core developers to generate, merge, split, edit, and extract pdf content easily in C#, F#, and VB.NET for .NET Core and .NET Framework, as well as create PDFs from HTML, ASPX, CSS, JS, and image files.
IronPDF makes use of an embedded, full Chromium based web browser renderer to convert HTML to PDF. This allows developers to generate PDFs from HTML, images, and CSS and to work closely with existing web assets and work in parallel with designers during a project.
IronPDF focuses on developer productivity. The Library simplifies many common complex PDF code tasks into convenient C# methods to extract text and images, sign PDFS, edit PDFs with new HTML and more - without the developer needing to study the PDF document standard to understand how to achieve their best result.
Let us have a look at some of their features.
IronPDF | SpirePDF |
---|---|
Convert HTML to PDF in C# using IronPDF | Spire.PDF for .NET supports converting HTML in C# |
URL to PDF in 3 lines of code | Required a workaround to try to convert from URL |
Easy HTML String to PDF conversion | Can convert HTML String to PDF |
Icon Fonts (Fontello, Bootstrap, FontAwesome) | 14 Core Fonts Type 1 Fonts Type 3 Fonts CJK Fonts True Type Fonts Unicode Support |
Licenses from $749 | Licenses from $599 |
License option | IronPDF | SpirePDF |
---|---|---|
1 developer, 1 location | $749 | $599 |
1 developer, unlimited projects, 1 location | $699 | $599 |
Up to 10 developers, unlimited projects, up to 10 locations | $1199 | $3070 |
Unlimited developers, unlimited project, unlimited locations | $1799 | No License |
1 SaaS/OEM product, up to 50 developers, unlimited locations | $1599 | $8988 |
Purchase a license | IronPDF Licensing Options | SpirePDF Licensing Options |
Now, let the code do the talking!
First, we will create a project to test different PDF functions using each software library.
Create an ASP.NET website using the following steps:
The next screen appears and from it, select Web Forms as shown below
There are two main ways to install IronPDF on your PC, they are shown below:
There are essentially three ways to quickly install the IronPDF NuGet package in your Visual Studio projects, they are:
The NuGet Package Manager is used to download and install various packages that you can include in your applications to improve their functionality. One such package is IronPDF. In order to download and install the IronPDF NuGet Package, select the Project Menu, or right click your project in the Solution Explorer. A screenshot of each is shown next.
Browse for the IronPDF package and install it as shown below.
You can also install the IronPDF NuGet package by using the Developer Command Prompt. The next few steps explain how.
PM > Install-Package IronPdf
The following steps enable you to download IronPDF directly from NuGet:
The second way to install IronPDF is by downloading it directly by clicking here to download IronPDF.dll.
Reference the Library in your project by using the next steps:
There are three ways to install the SpirePDF NuGet package in your Visual Studio projects, they include:
In Visual Studio, search for SpirePDF and install the relevant packages, as shown next. (The steps are similar to what was shown earlier)
Or, in the Developer Command Prompt (as shown previously, enter the following command)
Install-Package Spire.PDF -Version 6.9.16
Or, download it directly from their website: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
You will have to register an account.
If everything went well, you should be all set up to start using the libraries.
The following code downloads a webpage and converts it to a PDF document.
The code that follows makes use of IronPDF to create a PDF from a URL - in this case: the description of the PDF format on Wikipedia. Customer headers and Footers are also included.
var Renderer = new IronPdf.ChromePdfRenderer();
// Create a PDF from an existing HTML
Renderer.RenderingOptions.MarginTop = 50; //millimetres
Renderer.RenderingOptions.MarginBottom = 50;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
CenterText = "{pdf-title}",
DrawDividerLine = true,
FontSize = 16
};
Renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
{
LeftText = "{date} {time}",
RightText = "Page {page} of {total-pages}",
DrawDividerLine = true,
FontSize = 14
};
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.EnableJavaScript = true;
Renderer.RenderingOptions.RenderDelay = 500; //milliseconds
using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");
PDF.SaveAs("wikipedia.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
// Create a PDF from an existing HTML
Renderer.RenderingOptions.MarginTop = 50; //millimetres
Renderer.RenderingOptions.MarginBottom = 50;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
CenterText = "{pdf-title}",
DrawDividerLine = true,
FontSize = 16
};
Renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
{
LeftText = "{date} {time}",
RightText = "Page {page} of {total-pages}",
DrawDividerLine = true,
FontSize = 14
};
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.EnableJavaScript = true;
Renderer.RenderingOptions.RenderDelay = 500; //milliseconds
using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");
PDF.SaveAs("wikipedia.pdf");
Dim Renderer = New IronPdf.ChromePdfRenderer()
' Create a PDF from an existing HTML
Renderer.RenderingOptions.MarginTop = 50 'millimetres
Renderer.RenderingOptions.MarginBottom = 50
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
Renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.CenterText = "{pdf-title}",
.DrawDividerLine = True,
.FontSize = 16
}
Renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.LeftText = "{date} {time}",
.RightText = "Page {page} of {total-pages}",
.DrawDividerLine = True,
.FontSize = 14
}
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
Renderer.RenderingOptions.EnableJavaScript = True
Renderer.RenderingOptions.RenderDelay = 500 'milliseconds
Dim PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format")
PDF.SaveAs("wikipedia.pdf")
The output file contains 12 pages and it rendered JavaScript and CSS exceptionally well. The resulting output is shown below:
Generating a PDF from a URL is a seemingly simple conversion, as we saw above. But due to a number of factors, our engineering team had difficulty trying to accomplish it with SpirePDF. There is not much documentation available on this, and as developers we tried to find a workaround.
In order to accomplish this, we believe that you have to download and install more tools, as referenced here: http://www.e-iceblue.com/Download/download-pdf-for-net-now.html
We still haven't figured it out. Instead, here is a code segment for a Console Application that you could use to achieve this after you have gone through the whole rigmarole of steps:
//Create a pdf document.
PdfDocument doc = new PdfDocument();
PdfPageSettings setting = new PdfPageSettings();
setting.Size = new SizeF(1000, 1000);
setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = true;
String url = "https://www.wikipedia.org/";
Thread thread = new Thread(() =>
{ doc.LoadFromHTML(url, false, false, false, setting, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
//Save pdf file.
doc.SaveToFile("output-wiki.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("output-wiki.pdf");
//Create a pdf document.
PdfDocument doc = new PdfDocument();
PdfPageSettings setting = new PdfPageSettings();
setting.Size = new SizeF(1000, 1000);
setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = true;
String url = "https://www.wikipedia.org/";
Thread thread = new Thread(() =>
{ doc.LoadFromHTML(url, false, false, false, setting, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
//Save pdf file.
doc.SaveToFile("output-wiki.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("output-wiki.pdf");
'Create a pdf document.
Dim doc As New PdfDocument()
Dim setting As New PdfPageSettings()
setting.Size = New SizeF(1000, 1000)
setting.Margins = New Spire.Pdf.Graphics.PdfMargins(20)
Dim htmlLayoutFormat As New PdfHtmlLayoutFormat()
htmlLayoutFormat.IsWaiting = True
Dim url As String = "https://www.wikipedia.org/"
Dim thread As New Thread(Sub()
doc.LoadFromHTML(url, False, False, False, setting, htmlLayoutFormat)
End Sub)
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
'Save pdf file.
doc.SaveToFile("output-wiki.pdf")
doc.Close()
'Launching the Pdf file.
System.Diagnostics.Process.Start("output-wiki.pdf")
IronPDF needed three lines of code (if you include the SaveAs method at the bottom of the code segment as well), but otherwise just two lines were needed:
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format")
Quick and to the point. As you may have noticed, the code doesn’t make use of a FileStream or any additional .NET objects; RenderUrlAsPdf method handles all the complexities of the .NET Framework behind the scenes.
SpirePDF, on the other hand, made it very complicated to achieve the task of converting URL to PDF and required creative workarounds.
We will compare IronPDF and Spire.PDF on their conversion quality.
Spire.PDF for .NET is an API used to manipulate PDF files like IronPDF but does not provide as many features as IronPDF as well as quality of IronPDF renderer. The best way to compare two tools is the side-by-side comparison. Above are the output of both IronPDF and Spire.PDF. Bucket Admin panel is a web dashboard which is used to show all the useful information.
There is a clear difference in the rendering quality of both tools. IronPDF’s generated output is an 100% identical copy of the original webpage. On the other hand the PDF created by Spire.PDF is like just the skeleton of the website.
IronPDF used and rendered all the CSS and JavaScript of the webpage and is perfect looking but Spire.PDF miss nearly all the CSS and JavaScript files of the bucket Admin webpage. All the graphs are missing - If they are not missing their values, they are not calculated and shown by output.
Spire.PDF rendering engine does not render color accurately at all on the website; only a few colors can be seen on the output created by Spire.PDF. IronPDF makes an identical copy of the webpage and all the colors are pixel by pixel perfect.
In the Spire.PDF output file the side navigation bar cannot be identified and looks like there is only text situated in the place of the bar. In the IronPDF output file side navigation bar is perfect.
Both C# API IronPDF and Spire.PDF nearly take the same time to convert URL to PDF file but IronPDF renders all the content of the website accurately and Spire.PDF rendering engine can not create good quality PDF’s.
The following examples make use of IronPDF and SpirePDF to create a PDF document with a supplied HTML string.
The following code makes use of IronPDF to create a PDF containing HTML input.
/**
PDF from HTML String
anchor-pdf-from-html-string-with-ironpdf
**/
private void HTMLString()
{
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hi there IronPdf</h1>");
Renderer.RenderingOptions.TextFooter = new HtmlHeaderFooter() { HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>" };
var OutputPath = "ChromePdfRenderer.pdf";
PDF.SaveAs(OutputPath);
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
}
/**
PDF from HTML String
anchor-pdf-from-html-string-with-ironpdf
**/
private void HTMLString()
{
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hi there IronPdf</h1>");
Renderer.RenderingOptions.TextFooter = new HtmlHeaderFooter() { HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>" };
var OutputPath = "ChromePdfRenderer.pdf";
PDF.SaveAs(OutputPath);
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
}
'''
'''PDF from HTML String
'''anchor-pdf-from-html-string-with-ironpdf
'''*
Private Sub HTMLString()
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Hi there IronPdf</h1>")
Renderer.RenderingOptions.TextFooter = New HtmlHeaderFooter() With {.HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>"}
Dim OutputPath = "ChromePdfRenderer.pdf"
PDF.SaveAs(OutputPath)
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen
End Sub
The following code uses SpirePDF to create a PDF containing HTML text.
private void HTMLString()
{
Document document = new Document();
document.LoadFromFile("sample.htm", FileFormat.Html, XHTMLValidationType.None);
//Save html to PDF.
document.SaveToFile("Sample.pdf", FileFormat.PDF);
}
private void HTMLString()
{
Document document = new Document();
document.LoadFromFile("sample.htm", FileFormat.Html, XHTMLValidationType.None);
//Save html to PDF.
document.SaveToFile("Sample.pdf", FileFormat.PDF);
}
Private Sub HTMLString()
Dim document As New Document()
document.LoadFromFile("sample.htm", FileFormat.Html, XHTMLValidationType.None)
'Save html to PDF.
document.SaveToFile("Sample.pdf", FileFormat.PDF)
End Sub
SpirePDF seems to only be able to load HTML files by using the LoadFromFile method and then makes use of the SaveToFile call to send an HTML file to be output as a PDF.
IronPDF uses the RenderHtmlAsPdf to render the given HTML string in PDF format.
The next IronPDF and SpirePDF code creates a PDF document from an ASPX page.
The following code makes use of IronPDF to create a PDF document from an ASPX file.
/**
ASPX to PDF
anchor-aspx-to-pdf-with-ironpdf
**/
protected void Page_Load(object sender, EventArgs e)
{
IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
/**
ASPX to PDF
anchor-aspx-to-pdf-with-ironpdf
**/
protected void Page_Load(object sender, EventArgs e)
{
IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
'''
'''ASPX to PDF
'''anchor-aspx-to-pdf-with-ironpdf
'''*
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
IronPdf.AspxToPdf.RenderThisPageAsPdf()
End Sub
The following code would convert an ASPX file to PDF.
protected void Page_Load(object sender, EventArgs e)
{
using PdfDocument pdf = new PdfDocument();
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.RenderControl(htw);
//string sourceCode = sw.ToString();
string url=Request.Url.AbsoluteUri;
Thread thread = new Thread(() =>
{
PdfPageSettings settings = new PdfPageSettings();
PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat();
pdf.LoadFromHTML(url, false, true, true, settings, format);
//pdf.LoadFromHTML(Request.Url.AbsoluteUri, false, true, true);
});
pdf.SaveToHttpResponse("NameOfFile.pdf", Response, HttpReadType.Save);
}
protected void Page_Load(object sender, EventArgs e)
{
using PdfDocument pdf = new PdfDocument();
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.RenderControl(htw);
//string sourceCode = sw.ToString();
string url=Request.Url.AbsoluteUri;
Thread thread = new Thread(() =>
{
PdfPageSettings settings = new PdfPageSettings();
PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat();
pdf.LoadFromHTML(url, false, true, true, settings, format);
//pdf.LoadFromHTML(Request.Url.AbsoluteUri, false, true, true);
});
pdf.SaveToHttpResponse("NameOfFile.pdf", Response, HttpReadType.Save);
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Using pdf As New PdfDocument()
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
Me.RenderControl(htw)
'string sourceCode = sw.ToString();
Dim url As String=Request.Url.AbsoluteUri
Dim thread As New Thread(Sub()
Dim settings As New PdfPageSettings()
Dim format As New PdfHtmlLayoutFormat()
pdf.LoadFromHTML(url, False, True, True, settings, format)
'pdf.LoadFromHTML(Request.Url.AbsoluteUri, false, true, true);
End Sub)
pdf.SaveToHttpResponse("NameOfFile.pdf", Response, HttpReadType.Save)
End Using
End Sub
There are some caveats though: It may sometimes end up creating a blank PDF as Forms Authentication Membership is not supported.
The following code takes XML and converts it to a PDF document
/**
XML to PDF
anchor-xml-to-pdf-with-ironpdf
**/
private void XMLtoPDF(string XSLT, string XML)
{
XslCompiledTransform transform = new XslCompiledTransform();
using(XmlReader reader = XmlReader.Create(new StringReader(XSLT)))
{
transform.Load(reader);
}
StringWriter results = new StringWriter();
using(XmlReader reader = XmlReader.Create(new StringReader(XML)))
{
transform.Transform(reader, null, results);
}
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("XMLtoPDF.pdf");
}
/**
XML to PDF
anchor-xml-to-pdf-with-ironpdf
**/
private void XMLtoPDF(string XSLT, string XML)
{
XslCompiledTransform transform = new XslCompiledTransform();
using(XmlReader reader = XmlReader.Create(new StringReader(XSLT)))
{
transform.Load(reader);
}
StringWriter results = new StringWriter();
using(XmlReader reader = XmlReader.Create(new StringReader(XML)))
{
transform.Transform(reader, null, results);
}
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("XMLtoPDF.pdf");
}
'''
'''XML to PDF
'''anchor-xml-to-pdf-with-ironpdf
'''*
Private Sub XMLtoPDF(ByVal XSLT As String, ByVal XML As String)
Dim transform As New XslCompiledTransform()
Using reader As XmlReader = XmlReader.Create(New StringReader(XSLT))
transform.Load(reader)
End Using
Dim results As New StringWriter()
Using reader As XmlReader = XmlReader.Create(New StringReader(XML))
transform.Transform(reader, Nothing, results)
End Using
Dim Renderer As New IronPdf.ChromePdfRenderer()
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("XMLtoPDF.pdf")
End Sub
Pricing is most likely the number one deciding factor when deciding which product to buy. In the table, I'll quickly highlight the various options for IronPDF and SpirePDF.
See the Pricing Comparison Chart
Next, let’s compare the support and updates for Iron Software and SpirePDF.
The following support services are available:
Explore the API Reference for IronPDF C# Library, including details of all of IronPDF’s features, classes, method fields, namespaces, and enums.
View the API Reference9 .NET API products for your office documents