Skip to footer content
USING IRONPDF

How to Create PDF Files in .NET Using IronPDF

This tutorial demonstrates how to create a PDF file using the .NET language in just one line of source code with the IronPDF library.

Topics Covered In This Tutorial

The tutorial will cover the following topics:

  • PDF Library for PDF File Creation - IronPDF
  • Create a C# .NET Core Project
  • Install IronPDF
    1. NuGet Package Manager
    2. NuGet Package Manager Console
    3. Using DLL File
  • Add the IronPDF Namespace
  • Create a New PDF Document
    1. Create a PDF Document Using HTML String
    2. Create a PDF Document Using the HTML File Name
    3. Create a PDF Document Using a URL
  • Summary

IronPDF

IronPDF .NET PDF Library allows developers to create PDF files easily in C#, F#, and VB.NET for .NET Core and .NET Framework. IronPDF's rendering is "pixel perfect" to desktop versions of Google Chrome and easily creates PDF documents using a single line of code. It processes PDF documents without Acrobat Reader or any other PDF viewer. IronPDF can be used for creating PDF files using an HTML string, HTML file, or URL. IronPDF is a free library for the first 30 days that is used to create PDFs.

Some Important Features of IronPDF .NET Library

Let's start with how to use IronPDF to create PDF documents.

Create a C# Project

This tutorial will use the latest version of Visual Studio.

  • Open Visual Studio.
  • Create a new C# .NET Core project. Select .NET Core Console Application.

    How to Create PDF Files in .NET Using IronPDF, Figure 1: Console Application Console Application

  • Give a name to the project. E.g., DemoApp.
  • Select the latest and most stable version of the .NET Framework, which is 6.0. Click on the Create button.

    How to Create PDF Files in .NET Using IronPDF, Figure 2: .NET Framework .NET Framework

Install the IronPDF Library

To create a PDF document, firstly, install the IronPDF library. You can install it by any given method below.

1. NuGet Package Manager

The simplest approach is to install the IronPDF C# .NET Core Library from the NuGet Package Manager.

  • Open the Package Manager by clicking on Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
  • Or right-click on the project in Solution Explorer and click Manage NuGet Packages.

    How to Create PDF Files in .NET Using IronPDF, Figure 3: Package Manager - Solution Explorer Package Manager - Solution Explorer

  • Search for IronPDF. Select IronPDF and click on Install. The library will begin installing.

    How to Create PDF Files in .NET Using IronPDF, Figure 4: Install IronPDF Install IronPDF

2. NuGet Package Manager Console

Open the NuGet Package Manager Console by clicking on Tools > NuGet Package Manager > Package Manager Console. Type the following command in the command-line:

Install-Package IronPdf

How to Create PDF Files in .NET Using IronPDF, Figure 5: Package Manager Console Package Manager Console

3. Using a DLL File

The third way to use IronPDF in your project is to add a DLL file from the IronPDF library. You can download the IronPDF DLL file directly from this website.

  • Download the DLL zip file. Extract it to a specific folder.
  • Open a project in Visual Studio. In the Solution Explorer, right-click on References and browse for the IronPDF DLL file.

Add the IronPDF Namespace

Once the installation is done, add the IronPdf namespace to your program file.

using IronPdf;
using IronPdf;
Imports IronPdf
$vbLabelText   $csharpLabel

Note: You must add this line of code to every file where you wish to use IronPDF's features.

Create a New PDF Document

IronPDF is ready, and let's create PDF documents using this .NET Core application. There are multiple ways to create PDF documents. Let's have a look at some of them below using code examples.

1. Create a PDF File Using HTML String

The IronPDF library makes it very easy to process HTML strings and convert them into PDF format. Here is the code that easily creates PDFs.

// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();

// Use the renderer to convert HTML to a PDF
using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");

// Save the rendered PDF to a file
pdf.SaveAs("pixel-perfect.pdf");
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();

// Use the renderer to convert HTML to a PDF
using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");

// Save the rendered PDF to a file
pdf.SaveAs("pixel-perfect.pdf");
' Create a new instance of ChromePdfRenderer
Dim renderer = New ChromePdfRenderer()

' Use the renderer to convert HTML to a PDF
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>")

' Save the rendered PDF to a file
pdf.SaveAs("pixel-perfect.pdf")
$vbLabelText   $csharpLabel

This code will generate a PDF file containing the content passed in the RenderHtmlAsPdf method. This function performs the conversion of an HTML fragment to a PDF document. You must be familiar with HTML tags to generate PDF files or PDF pages using the IronPDF library. The SaveAs method is used to save the output PDF file. You can see the output PDF page below.

Output

How to Create PDF Files in .NET Using IronPDF, Figure 6: HTML String to PDF HTML String to PDF

2. Create PDF Using HTML File Name

The IronPDF library provides a fantastic feature to create a PDF file from an HTML file. IronPDF directly converts everything in an HTML document, including images, CSS, forms, etc., to a PDF document. It does not require any other library or function for further processing. IronPDF directly converts any HTML file to a PDF file.

Let's look at the following code for creating a PDF file from an HTML file:

// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();

// Render an HTML file to a PDF document
var pdf = renderer.RenderHtmlFileAsPdf("IronFile.html");

// Save the rendered PDF to a file
pdf.SaveAs("IronPDF.pdf");
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();

// Render an HTML file to a PDF document
var pdf = renderer.RenderHtmlFileAsPdf("IronFile.html");

// Save the rendered PDF to a file
pdf.SaveAs("IronPDF.pdf");
' Create a new instance of ChromePdfRenderer
Dim renderer = New ChromePdfRenderer()

' Render an HTML file to a PDF document
Dim pdf = renderer.RenderHtmlFileAsPdf("IronFile.html")

' Save the rendered PDF to a file
pdf.SaveAs("IronPDF.pdf")
$vbLabelText   $csharpLabel

Here, the RenderHtmlFileAsPdf method is used to create a PDF from HTML files. You can provide the full path of the HTML file in the function parameter, or place the HTML file in the bin folder of the source code and just provide the file name with the extension. The output PDF file will be saved in the bin folder. The SaveAs function allows you to save the created PDF file. You can check other .NET Core rendering options with header and footer options from this IronPDF rendering options tutorial.

3. Create PDF Using URLs

Sometimes, there is a need to create PDF files of a URL programmatically in the application. You can use any URL to create a PDF document and return a file in the IronPDF library.

This is the sample code:

// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();

// Render a URL to a PDF document
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

// Save the rendered PDF to a file
pdf.SaveAs("IronPDF PDF Library.pdf");
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();

// Render a URL to a PDF document
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

// Save the rendered PDF to a file
pdf.SaveAs("IronPDF PDF Library.pdf");
' Create a new instance of ChromePdfRenderer
Dim renderer = New ChromePdfRenderer()

' Render a URL to a PDF document
Dim pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")

' Save the rendered PDF to a file
pdf.SaveAs("IronPDF PDF Library.pdf")
$vbLabelText   $csharpLabel

The above code will create a PDF file from the given URL parameter passed to the RenderUrlAsPdf method. This function creates a PDF document of the URL. The SaveAs function is used for saving output files in the bin folder. You can see the bin folder in your project folder.

Output

How to Create PDF Files in .NET Using IronPDF, Figure 7: URL to PDF Document URL to PDF Document

Summary

IronPDF is a complete solution for working with PDF documents. It provides the ability to convert from different formats to PDF. The manipulation and formatting of PDF files become very easy with the IronPDF library function. All that is required is just a few lines of code to create and format the PDF file programmatically. Its main highlight is the HTML converter, and it does not render HTML to PDF from a remote server. It spins up an instance of a real standards-compliant web browser behind the scenes (without any additional software needing to be installed). The HTML is rendered with complete accuracy --- and in a vector format suitable for the highest standards of commercial printing. The output is a clean and high-quality PDF. IronPDF is ideal for developers and companies who need to manipulate PDF files within their software. It is openly commercial, with licensing and pricing details all published on the website.

You can try this PDF library's free version to test out its functionality. There is a free trial key to test out the full potential of IronPDF and generate PDF documents in your applications. Further, the current special offer allows you to get five products by IronPDF for the price of just two. More information about licensing can be found on this IronPDF licensing page.

Frequently Asked Questions

What is the main purpose of this .NET PDF library?

IronPDF is a .NET PDF Library that allows developers to create PDF files easily in C#, F#, and VB.NET for .NET Core and .NET Framework. It provides 'pixel perfect' rendering to create PDF documents using a single line of code without requiring third-party PDF viewers.

How can I install this PDF library in a .NET project?

You can install the IronPDF library using the NuGet Package Manager, NuGet Package Manager Console, or by adding a DLL file to your project.

What are the different methods to create a PDF document with this library?

IronPDF allows you to create a PDF document using an HTML string, an HTML file, or a URL. These methods provide flexibility in how you generate PDF files from different sources.

Can this library convert HTML to PDF?

Yes, IronPDF can convert HTML to PDF using its rendering engine, which allows for the conversion of HTML strings, HTML files, and even URLs to PDF format.

What programming languages are compatible with this PDF library?

IronPDF is compatible with C#, F#, and VB.NET, making it suitable for developers working within the .NET ecosystem.

Is there a trial available for this PDF library?

Yes, IronPDF offers a free trial that allows you to test its full functionality for 30 days before making a purchase.

Does this library require any third-party software to work?

No, IronPDF does not require any third-party PDF viewers like Acrobat Reader. It operates independently to create and manipulate PDF documents.

Can this library handle advanced PDF features like form filling and digital signatures?

Yes, IronPDF supports advanced features such as reading and filling out PDF form fields, extracting images and text, and digitally signing PDF documents.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.