Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
IronPDF and iText 7 (formerly known as iTextSharp) both provide the ability generate, manipulate, and print PDFs in .NET and .NET Core.
Which C# PDF library is best suited for your .NET project? The goal of this article is to help readers make a proper and informed decision.
HtmlConverter.ConvertToPDF
method to convert an HTML file into a PDF fileIronPDF is:
iText (iTextSharp) is:
iTextSharp has been around for at least 6 years, based on an open source Java codebase called iText, and still has somewhat of a Java flavor. Developers who first learned Java may find this library familiar.
IronPDF is a .NET-first library with an API designed around ease of use in Visual Studio. .NET has been in existence for almost 20 years, continually growing and expanding, and opening up many possibilities, which IronPDF is designed to leverage. It allows us to create and manipulate PDF documents in .NET framework projects. You can download IronPDF as an iTextSharp Alternative.
The rendering API of iText and IronPDF are quite different. Let's compare each code segment to add headers and footers to a PDF document.
Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
CenterText = "{pdf-title}",
DrawDividerLine = true,
FontSize = 16
};
Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "{date} {time}",
RightText = "Page {page} of {total-pages}",
DrawDividerLine = true,
FontSize = 14
};
Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
CenterText = "{pdf-title}",
DrawDividerLine = true,
FontSize = 16
};
Renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "{date} {time}",
RightText = "Page {page} of {total-pages}",
DrawDividerLine = true,
FontSize = 14
};
Renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.CenterText = "{pdf-title}",
.DrawDividerLine = True,
.FontSize = 16
}
Renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.LeftText = "{date} {time}",
.RightText = "Page {page} of {total-pages}",
.DrawDividerLine = True,
.FontSize = 14
}
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(16);
document.Add(header);
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
Rectangle pageSize = pdf.GetPage(i).GetPageSize();
float x = pageSize.GetWidth() / 2;
float y = pageSize.GetTop() - 20;
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
}
document.SetTopMargin(50);
document.SetBottomMargin(50);
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(16);
document.Add(header);
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
Rectangle pageSize = pdf.GetPage(i).GetPageSize();
float x = pageSize.GetWidth() / 2;
float y = pageSize.GetTop() - 20;
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
}
document.SetTopMargin(50);
document.SetBottomMargin(50);
Dim header As Paragraph = (New Paragraph("HEADER")).SetTextAlignment(TextAlignment.CENTER).SetFontSize(16)
document.Add(header)
Dim i As Integer = 1
Do While i <= pdf.GetNumberOfPages()
Dim pageSize As Rectangle = pdf.GetPage(i).GetPageSize()
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
Dim x As Single = pageSize.GetWidth() / 2
Dim y As Single = pageSize.GetTop() - 20
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0)
i += 1
Loop
document.SetTopMargin(50)
document.SetBottomMargin(50)
By quickly glancing at the code, you can see that IronPDF is pragmatic, based on common end user requirements.
iText is a lower level library which focuses on a drawing API where we add objects, shapes, and text to pages.
iTextSharp.dll uses a primarily programmatic model to render PDFs. When using the iTextSharp PDF library, each piece of PDF text, graphic, table or line is “plotted” or drawn onto a PDF. The API appears low level and is focused on the PDF document standard. This model allows precision, but may require developers to learn a little about how PDFs work. Closely matching an existing design styles or web assets may take some of iteration and reading the iTextSharp documentation. In keeping with its heritage, the methodology and programmatic interface has a distinct Java flavor.
In contrast, IronPDF uses a full embedded web browser renderer to convert HTML to PDF. Following short (1- and 2-line) C# code examples, developers can generate PDFs from existing or new HTML, images and CSS. This allows developers to work closely with existing web assets and also work in parallel with designers during a project. iText does include HTML to PDF functionality for C# .NET, though it is not, apparently, the library's dominant feature.
Read on for more comparative details on the different ways that IronPDF and iTextSharp can help developers achieve the following goals:
Licensing options are also an important factor to developer projects. iTextSharp is Open Source under the AGPL license agreement. When licensed under AGLP, anyone who uses any part of an application which contains iTextSharp (even across a company network or the internet) may be entitled to a full copy of the app's full source code. This is excellent for academic work. If we wish to use iTextSharp in commercial applications it is best practice to contact iText and ask them for a quote on the pricing for iText commercial usage.
IronPDF is free for development, and can then be licensed for commercial deployment at publicly published, reasonable prices starting at $749.
This is how the 2 libraries stack up:
Convert HTML to PDF via a full built-in web browser | Basic HTML to PDF via a pdfHTML add-on |
Rendering focus: Embedded web browser | Rendering focus: Programmatic drawing model |
IronPDF has explicit licenses with published prices | AGPL! Commercial use pricing not published. |
Easy to Code with .NET First Design | Based on a Java API |
Not suited to academic assignments and coursework | Excellent for academic assignments and research |
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.
It makes use of a fully embedded web browser 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 also work in parallel with designers during a project.
IronPDF really 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.
The iTextSharp.dll uses a primarily programmatic model to render PDFs, and it has advanced PDF manipulation APIs that are powerful and follow the PDF standard closely.
Let's compare by creating an example project utilizing both libraries:
Make use of the following steps to create an ASP.NET website:
Now we have something to work with. Let’s Install IronPDF.
In order to make use of IronPDF, you first need to install it (free). There are two options:
Let’s have a closer look.
Install-Package IronPdf
There are three ways to install the IronPDF NuGet package:
Let’s do them one-by-one.
Visual Studio provides the NuGet Package Manager for you to install NuGet packages in your projects. You can access it via the Project Menu, or by right clicking your project in the Solution Explorer. Both these options are shown below in Figures 3 and 4
After you have clicked Manage NuGet Packages from either option, Browse for the IronPDF package and install it as shown in Figure 5.
The following steps opens the Developer Command Prompt and installs the IronPDF NuGet package
In order to download the NuGet package:
The second way to install IronPDF is by direct download.
Reference the Library in your project by using the next steps:
Now that you’re set up, we can start playing with the awesome features in the IronPDF library after the setup for iTextSharp.
There are three ways to install the iTextSharp NuGet package, they are:
Let’s do them one-by-one.
For Visual Studio, search for iText and install the relevant packages, as shown next.
Or, in the Developer Command Prompt (as shown previously, enter the following command)
Or, download iText 7 directly from their website.
Now that you have created the necessary projects, let’s compare these two libraries in code.
The following code downloads a webpage and converts it to a PDF document.
The following code is using IronPDF to create a PDF document directly from a website address. Custom Headers and Footers are also included.
/**
IronPDF URL to PDF
anchor-ironpdf-website-to-pdf
**/
private void ExistingWebURL()
{
// Create a PDF from any existing web page
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");
}
/**
IronPDF URL to PDF
anchor-ironpdf-website-to-pdf
**/
private void ExistingWebURL()
{
// Create a PDF from any existing web page
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");
}
'''
'''IronPDF URL to PDF
'''anchor-ironpdf-website-to-pdf
'''*
Private Sub ExistingWebURL()
' Create a PDF from any existing web page
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")
End Sub
The following code uses iText7 to create a PDF document directly from a website address and add headers and footers.
/**
iText URL to PDF
anchor-itext-url-to-pdf
**/
private void ExistingWebURL()
{
//Initialize PDF writer
PdfWriter writer = new PdfWriter("wikipedia.pdf");
//Initialize PDF document
using PdfDocument pdf = new PdfDocument(writer);
ConverterProperties properties = new ConverterProperties();
properties.SetBaseUri("https://en.wikipedia.org/wiki/Portable_Document_Format");
Document document = HtmlConverter.ConvertToDocument(new FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties);
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(16);
document.Add(header);
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
Rectangle pageSize = pdf.GetPage(i).GetPageSize();
float x = pageSize.GetWidth() / 2;
float y = pageSize.GetTop() - 20;
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
}
document.SetTopMargin(50);
document.SetBottomMargin(50);
document.Close();
}
/**
iText URL to PDF
anchor-itext-url-to-pdf
**/
private void ExistingWebURL()
{
//Initialize PDF writer
PdfWriter writer = new PdfWriter("wikipedia.pdf");
//Initialize PDF document
using PdfDocument pdf = new PdfDocument(writer);
ConverterProperties properties = new ConverterProperties();
properties.SetBaseUri("https://en.wikipedia.org/wiki/Portable_Document_Format");
Document document = HtmlConverter.ConvertToDocument(new FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties);
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(16);
document.Add(header);
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
Rectangle pageSize = pdf.GetPage(i).GetPageSize();
float x = pageSize.GetWidth() / 2;
float y = pageSize.GetTop() - 20;
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
}
document.SetTopMargin(50);
document.SetBottomMargin(50);
document.Close();
}
'''
'''iText URL to PDF
'''anchor-itext-url-to-pdf
'''*
Private Sub ExistingWebURL()
'Initialize PDF writer
Dim writer As New PdfWriter("wikipedia.pdf")
'Initialize PDF document
Using pdf As New PdfDocument(writer)
Dim properties As New ConverterProperties()
properties.SetBaseUri("https://en.wikipedia.org/wiki/Portable_Document_Format")
Dim document As Document = HtmlConverter.ConvertToDocument(New FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties)
Dim header As Paragraph = (New Paragraph("HEADER")).SetTextAlignment(TextAlignment.CENTER).SetFontSize(16)
document.Add(header)
Dim i As Integer = 1
Do While i <= pdf.GetNumberOfPages()
Dim pageSize As Rectangle = pdf.GetPage(i).GetPageSize()
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
Dim x As Single = pageSize.GetWidth() / 2
Dim y As Single = pageSize.GetTop() - 20
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0)
i += 1
Loop
document.SetTopMargin(50)
document.SetBottomMargin(50)
document.Close()
End Using
End Sub
With iText 7, it took the author longer to develop code to convert the document at the given URL to PDF. Two lines of code are needed:
MemoryStream wiki = GetStreamFromUrl("https://en.wikipedia.org/wiki/Tiger");
HtmlConverter.ConvertToPdf(wiki, new FileStream("wikipedia.pdf",FileMode.OpenOrCreate));
MemoryStream wiki = GetStreamFromUrl("https://en.wikipedia.org/wiki/Tiger");
HtmlConverter.ConvertToPdf(wiki, new FileStream("wikipedia.pdf",FileMode.OpenOrCreate));
Dim wiki As MemoryStream = GetStreamFromUrl("https://en.wikipedia.org/wiki/Tiger")
HtmlConverter.ConvertToPdf(wiki, New FileStream("wikipedia.pdf",FileMode.OpenOrCreate))
A MemoryStream object as well as a FileStream object have to be created with set properties.
Let's have a look at IronPDF.
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");
PDF.SaveAs("wikipedia.pdf")
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");
PDF.SaveAs("wikipedia.pdf")
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format")
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'PDF.SaveAs("wikipedia.pdf")
No need for a FileStream or an additional .NET object, as all the functionality seems to be built-in to the IronPdf RenderUrlAsPdf method.
I am including an Output comparison now, as this should apply to all the following exercises that we’ll do during this tutorial.
With this code segment we have transformed the Tiger Wikipedia webpage to PDF with both libraries.
The file that was output by using iText’s library has 49 pages. It didn’t render JavaScript nor CSS. The resulting output is shown below:
The file that was output by using IronPDF’s library has 12 pages. It rendered JavaScript and CSS quite well. The resulting output is shown below:
A picture tells a thousand words…. IronPDF shines at HTML to PDF rendering.
The next code creates a PDF document and prints an HTML string inside it.
The following code makes use of IronPDF to generate a PDF containing HTML input.
/**
IronPDF HTML to PDF
anchor-ironpdf-document-from-html
**/
private void HTMLString()
{
// Render any HTML fragment or document to HTML
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello 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;
}
/**
IronPDF HTML to PDF
anchor-ironpdf-document-from-html
**/
private void HTMLString()
{
// Render any HTML fragment or document to HTML
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello 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;
}
'''
'''IronPDF HTML to PDF
'''anchor-ironpdf-document-from-html
'''*
Private Sub HTMLString()
' Render any HTML fragment or document to HTML
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Hello 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 is using iText7 to create a PDF containing HTML text.
/**
iText HTML to PDF
anchor-itext-html-to-pdf
**/
private void HTMLString()
{
HtmlConverter.ConvertToPdf("< h1 > Hello iText7 </ h1 >", new FileStream("ChromePdfRenderer.pdf", FileMode.Create));
}
/**
iText HTML to PDF
anchor-itext-html-to-pdf
**/
private void HTMLString()
{
HtmlConverter.ConvertToPdf("< h1 > Hello iText7 </ h1 >", new FileStream("ChromePdfRenderer.pdf", FileMode.Create));
}
'''
'''iText HTML to PDF
'''anchor-itext-html-to-pdf
'''*
Private Sub HTMLString()
HtmlConverter.ConvertToPdf("< h1 > Hello iText7 </ h1 >", New FileStream("ChromePdfRenderer.pdf", FileMode.Create))
End Sub
iText makes use of the HtmlConverter.ConvertToPdf call again to send an HTML string to be output as a PDF.
IronPDF makes use of its RenderHtmlAsPdf method which is specifically designed to work with HTML and PDF.
Both options are quite quick and to the point, but IronPDF allowed a lot of control over the rendering process and even using HTML to add headers and footers to PDF Pages.
The next code creates a PDF document from an ASPX page.
The following code makes use of IronPDF to create a PDF containing from an ASPX file. The Web form becomes a dynamic PDF by adding 1 line of code to the Page_Load event. IronPdf.AspxToPdf.RenderThisPageAsPdf();
/**
IronPDF ASPX to PDF
anchor-ironpdf-render-pdf-from-aspx
**/
protected void Page_Load(object sender, EventArgs e)
{
IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
/**
IronPDF ASPX to PDF
anchor-ironpdf-render-pdf-from-aspx
**/
protected void Page_Load(object sender, EventArgs e)
{
IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
'''
'''IronPDF ASPX to PDF
'''anchor-ironpdf-render-pdf-from-aspx
'''*
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
IronPdf.AspxToPdf.RenderThisPageAsPdf()
End Sub
It seems as if the pdfHTML library of iText7 does not support creating PDFs from ASPX web pages. This functionality would need to be coded on a project-for-project basis.
The developer should get the HTML from the framework, then the pdfHTML add-on will accept that HTML for conversion to PDF.
The following code takes XML and converts it to PDF
/**
IronPDF XML to PDF
anchor-ironpdf-creates-pdf-from-xml
**/
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();
// options, headers, and footers may be set there
// Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("XMLtoPDF.pdf");
}
/**
IronPDF XML to PDF
anchor-ironpdf-creates-pdf-from-xml
**/
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();
// options, headers, and footers may be set there
// Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("XMLtoPDF.pdf");
}
'''
'''IronPDF XML to PDF
'''anchor-ironpdf-creates-pdf-from-xml
'''*
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()
' options, headers, and footers may be set there
' Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("XMLtoPDF.pdf")
End Sub
The structure of the XSLT file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<p>Titles:
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title"/>
<xsl:if test="position() < last()-1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position()=last()-1">
<xsl:text>, and </xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<xsl:text>!</xsl:text>
</xsl:if>
</xsl:for-each>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<p>Titles:
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title"/>
<xsl:if test="position() < last()-1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position()=last()-1">
<xsl:text>, and </xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<xsl:text>!</xsl:text>
</xsl:if>
</xsl:for-each>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
iText's support for processing XML to PDF may require custom development work.
The next code obtains data from an external source and creates a chart accordingly.
The following code uses IronPDF to quickly create a chart and set the page properties using HTML to PDF.
/**
IronPDF Create Chart
anchor-ironpdf-chart-creation
**/
private void Chart()
{
var Renderer = new ChromePdfRenderer();
using var PDF = Renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006");
Renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
Renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
PDF.SaveAs("chart.pdf");
}
/**
IronPDF Create Chart
anchor-ironpdf-chart-creation
**/
private void Chart()
{
var Renderer = new ChromePdfRenderer();
using var PDF = Renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006");
Renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
Renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
PDF.SaveAs("chart.pdf");
}
'''
'''IronPDF Create Chart
'''anchor-ironpdf-chart-creation
'''*
Private Sub Chart()
Dim Renderer = New ChromePdfRenderer()
Dim PDF = Renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006")
Renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4
Renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape
PDF.SaveAs("chart.pdf")
End Sub
The following code uses iText7 to create a chart and set properties. We can see a programmatic drawing-api style.
/**
iText Create Chart
anchor-itext-c-charts
**/
private void Chart()
{
//Initialize PDF writer
PdfWriter writer = new PdfWriter("chart.pdf");
//Initialize PDF document
using PdfDocument pdf = new PdfDocument(writer);
ConverterProperties properties = new ConverterProperties();
properties.SetBaseUri("https://bl.ocks.org/mbostock/4062006");
Document document = HtmlConverter.ConvertToDocument(new FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties);
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(16);
document.Add(header);
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
Rectangle pageSize = pdf.GetPage(i).GetPageSize();
float x = pageSize.GetWidth() / 2;
float y = pageSize.GetTop() - 20;
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
}
document.Close();
}
/**
iText Create Chart
anchor-itext-c-charts
**/
private void Chart()
{
//Initialize PDF writer
PdfWriter writer = new PdfWriter("chart.pdf");
//Initialize PDF document
using PdfDocument pdf = new PdfDocument(writer);
ConverterProperties properties = new ConverterProperties();
properties.SetBaseUri("https://bl.ocks.org/mbostock/4062006");
Document document = HtmlConverter.ConvertToDocument(new FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties);
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(16);
document.Add(header);
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
Rectangle pageSize = pdf.GetPage(i).GetPageSize();
float x = pageSize.GetWidth() / 2;
float y = pageSize.GetTop() - 20;
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
}
document.Close();
}
'''
'''iText Create Chart
'''anchor-itext-c-charts
'''*
Private Sub Chart()
'Initialize PDF writer
Dim writer As New PdfWriter("chart.pdf")
'Initialize PDF document
Using pdf As New PdfDocument(writer)
Dim properties As New ConverterProperties()
properties.SetBaseUri("https://bl.ocks.org/mbostock/4062006")
Dim document As Document = HtmlConverter.ConvertToDocument(New FileStream("Test_iText7_1.pdf", FileMode.Open), pdf, properties)
Dim header As Paragraph = (New Paragraph("HEADER")).SetTextAlignment(TextAlignment.CENTER).SetFontSize(16)
document.Add(header)
Dim i As Integer = 1
Do While i <= pdf.GetNumberOfPages()
Dim pageSize As Rectangle = pdf.GetPage(i).GetPageSize()
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
Dim x As Single = pageSize.GetWidth() / 2
Dim y As Single = pageSize.GetTop() - 20
document.ShowTextAligned(header, x, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0)
i += 1
Loop
document.Close()
End Using
End Sub
The biggest difference between IronPDF's and iText's licensing options is the fact that iTextSharp is Open Source under the AGPL license agreement. In short (as quoted, "The AGPL license differs from the other GNU licenses in that it was built for network software. You can distribute modified versions if you keep track of the changes and the date you made them. As per usual with GNU licenses, you must license derivatives under AGPL. It provides the same restrictions and freedoms as the GPLv3 but with an additional clause which makes it so that source code must be distributed along with web publication. Since websites and services are never distributed in the traditional sense, the AGPL is the GPL of the web."
This means that if the application uses iTextSharp in any way - even over a local network OR over the internet, then the application’s full source code must be freely available to every user. That is not always in a project's best interest.
This license is often used for highly academic works that are intended to stay academic, and also for open source projects who intend paid usage for software deployed outside academic environments. The nature of the AGPL license agreement makes the open source iTextSharp license difficult for many commercial use cases, unless a private license can be arranged and legally negotiated with the developers.
IronPDF, on the other hand, is an openly commercial C# PDF library. It is free for development and can always be licensed for commercial deployment. This clear license model does not require developers to learn the ins and outs of GNU / AGPL license models and can instead focus on their projects. Licenses are available for single project use, single developers, agencies and global corporations, and SaaS and OEM redistribution. No legal fees negotiated, just straightforward licensing.
IronPdf is:
iText (iTextSharp) is:
You can access and share all the source code from this comparison tutorial in C# on GitHub.
IronPDF and iTextSharp Code ComparisonWe created a free PDF resource guide to help make developing PDFs easier for .NET, with walk-throughs of common functions and examples for manipulating, editing, generating, and saving PDFS in C# and VB.NET for your project.
Download the GuideExplore 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