Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
PDF documents are prevalent in today's culture, used by various enterprises for creating invoices and other documents. When selecting a .NET Library for projects, the ease of creating, reading, and writing PDF files should be considered.
IronPDF is one of the best HTML-to-PDF converters available on the market. IronPDF can handle almost any operation that a browser is capable of handling. It can create PDF files from HTML5, JavaScript, CSS, and images. The .NET PDF library makes it simple to produce/generate PDF files, read existing PDFs, and edit PDF files. Possible modifications include changing font sizes, pagination, text content, etc. Users of IronPDF can create form fields in rendered PDF documents.
IronPDF is compatible with all .NET Framework project types, including ASP.NET, Windows Forms, and other traditional Windows Application types. IronPDF is capable of rendering ASPX, Razor, and other MVC view components directly into PDFs.
IronPDF's full set of features include:
This article will demonstrate IronPDF's document generation abilities with a simple Console Application.
Open Visual Studio software and go to the File menu. Select "New project", and then select "Console App".
New Project
Specify the project name and its location. Click on the Next button and choose a .NET Framework.
.NET Framework Selection
Finally, click on Create to generate the new Visual Studio project.
.NET Program.cs
The IronPDF library can be downloaded and installed in four ways.
These four ways are:
The NuGet Package Manager is available in the Visual Studio software for easy installation of packages from NuGet. The below screenshot shows how to open the NuGet Package Manager GUI.
NuGet Package Manager
Search for "IronPDF" in the Browse tab of the Package Manager GUI.
IronPDF Installation
Choose the IronPdf
package (first option) and click on the Install button to add it to the Solution.
In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Console
Enter the following command in the Package Manager Console tab and press ENTER.
Install-Package IronPdf
Install IronPDF
Download the IronPDF ZIP file directly with the latest version of the IronPDF package.
Once downloaded, follow the steps below to add the package to the project.
The code example below shows how to create PDF files from the given HTML template with just a few lines of code.
using System;
using System.Collections.Generic;
using System.Text;
using IronPdf;
class Program
{
static void Main()
{
// Create an instance of ChromePdfRenderer
var renderer = new IronPdf.ChromePdfRenderer();
// Render the HTML as PDF and save it as Test.pdf
renderer.RenderHtmlAsPdf(BuildTemplate()).SaveAs("Test.pdf");
}
/// <summary>
/// Builds an HTML template string using StringBuilder
/// </summary>
/// <returns>HTML string representation of a table</returns>
static string BuildTemplate()
{
var builder = new StringBuilder();
builder.Append("<table border='1'>");
builder.Append("<tr>");
builder.Append("<th>");
builder.Append("Cat Family");
builder.Append("</th>");
builder.Append("</tr>");
// Iterate over the data and populate the table rows
foreach (var item in GetData())
{
builder.Append("<tr>");
builder.Append("<td>");
builder.Append(item.ToString());
builder.Append("</td>");
builder.Append("</tr>");
}
builder.Append("</table>");
return builder.ToString();
}
/// <summary>
/// Provides a list of data representing different members of the cat family
/// </summary>
/// <returns>List of strings</returns>
static List<string> GetData()
{
List<string> data = new List<string>
{
"Lion",
"Tiger",
"Cat",
"Cheetah",
"Lynx"
};
return data;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using IronPdf;
class Program
{
static void Main()
{
// Create an instance of ChromePdfRenderer
var renderer = new IronPdf.ChromePdfRenderer();
// Render the HTML as PDF and save it as Test.pdf
renderer.RenderHtmlAsPdf(BuildTemplate()).SaveAs("Test.pdf");
}
/// <summary>
/// Builds an HTML template string using StringBuilder
/// </summary>
/// <returns>HTML string representation of a table</returns>
static string BuildTemplate()
{
var builder = new StringBuilder();
builder.Append("<table border='1'>");
builder.Append("<tr>");
builder.Append("<th>");
builder.Append("Cat Family");
builder.Append("</th>");
builder.Append("</tr>");
// Iterate over the data and populate the table rows
foreach (var item in GetData())
{
builder.Append("<tr>");
builder.Append("<td>");
builder.Append(item.ToString());
builder.Append("</td>");
builder.Append("</tr>");
}
builder.Append("</table>");
return builder.ToString();
}
/// <summary>
/// Provides a list of data representing different members of the cat family
/// </summary>
/// <returns>List of strings</returns>
static List<string> GetData()
{
List<string> data = new List<string>
{
"Lion",
"Tiger",
"Cat",
"Cheetah",
"Lynx"
};
return data;
}
}
In the above code:
ChromePdfRenderer
class to access PDF creation features.RenderHtmlAsPdf
passing the HTML string built by the BuildTemplate
method. This method converts the HTML into a PDF.BuildTemplate
method uses a StringBuilder
to construct an HTML table populated with data.GetData
returns a list of strings representing the 'cat family', which fills the rows of the HTML table.Below is the sample PDF file, generated from the above code with just a few lines using the given template.
Generated PDF File
Any type of HTML tag can be used to create a template that can help the user generate user forms, receipts, etc., with a sample template but different data.
It is possible to use the method RenderUrlAsPdf
or RenderHtmlFileAsPdf
to generate PDF files from different sources. The former method accepts a URL to a webpage, while the latter accepts a string containing the location of an HTML file on the computer.
Read this tutorial for generating PDFs from HTML for more information.
Use IronPDF in production without a watermark with a free trial key. IronPDF comes with SaaS and OEM Redistribution licensing for an additional cost. To know more, refer to the IronPDF Licensing page.
IronPDF is a .NET library that allows developers to create, read, and edit PDF files. It can convert HTML, JavaScript, CSS, and images into PDF documents and supports various project types such as ASP.NET and Windows Forms.
You can generate a PDF from a template in C# by creating an HTML string with data placeholders, using IronPDF's RenderHtmlAsPdf method to convert the HTML into a PDF, and saving the generated PDF as a new document.
You can install IronPDF in a Visual Studio project via the NuGet Package Manager by searching for 'IronPDF' and installing it, or by using the Package Manager Console with the command 'Install-Package IronPdf'.
Yes, IronPDF can handle HTML5 and JavaScript, making it capable of converting complex web pages into PDF documents without losing formatting.
IronPDF can create PDFs from HTML markup, web pages, images, and even HTML files stored offline. It supports methods like RenderUrlAsPdf for URLs and RenderHtmlFileAsPdf for HTML files.
IronPDF offers features like merging and splitting PDFs, filling PDF forms programmatically, text and image extraction, and adding annotations, headers, footers, and watermarks to PDF documents.
Yes, IronPDF is compatible with all .NET Framework project types, including ASP.NET, Windows Forms, and other traditional Windows applications.
To create a new project in Visual Studio for using IronPDF, open Visual Studio, select 'New project', choose 'Console App', specify the project name and location, select a .NET Framework, and click 'Create'.
Yes, IronPDF can generate PDFs from web pages that are locked behind HTML login forms, providing flexibility in handling secure web content.