Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This tutorial demonstrates how to create a PDF file using the .NET language in just one line of source code with the IronPDF library.
The tutorial will cover the following topics:
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 HTML string, HTML file, or URL. IronPDF is a free library for the first 30 days that is used to create PDFs.
Let's start with how to use IronPDF to create PDF documents.
This tutorial will use the latest version of Visual Studio.
Create a new C# .NET Core project. Select .NET Core Console Application.
Console Application
Select the latest and most stable version of the .NET Framework is 6.0. Click on the Create button.
.NET Framework
To create a PDF document, firstly, install the IronPDF library. You can install it by any given method below.
The simplest approach is to install the IronPDF C# .NET Core Library from the NuGet Package Manager.
Or right-click on the project in Solution Explorer and click Manage NuGet Packages.
Package Manager - Solution Explorer
Search for IronPDF. Select IronPDF and click on the Install. The library will begin installing.
Install IronPDF
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
Package Manager Console
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.
Once the installation is done, now add the IronPdf
namespace to your program file.
using IronPdf;
using IronPdf;
Imports IronPdf
Note: You must add this line of code to every file where you wish to use IronPDF's features.
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.
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.
// Render any HTML fragment or document to HTML
var renderer = new ChromePdfRenderer();
using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
pdf.SaveAs("pixel-perfect.pdf");
// Render any HTML fragment or document to HTML
var renderer = new ChromePdfRenderer();
using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
pdf.SaveAs("pixel-perfect.pdf");
' Render any HTML fragment or document to HTML
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>")
pdf.SaveAs("pixel-perfect.pdf")
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.
HTML String to PDF
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:
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("IronFile.html");
pdf.SaveAs("IronPDF.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("IronFile.html");
pdf.SaveAs("IronPDF.pdf");
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlFileAsPdf("IronFile.html")
pdf.SaveAs("IronPDF.pdf")
Here, the RenderHtmlFileAsPdf method
is used to create PDF from HTML files, and it is the most important function in the above code. You can give the full path of the HTML file in the function parameter or just place the HTML file in the bin
folder of the source code. Then you will only need to put the file name with the extension in the RenderHtmlFileAsPdf
function's parameter. The output PDF file will be saved in the bin
folder when you run this code. The SaveAs
function will help you to save created PDF files.
You can check other .NET Core rendering options along with header footer options from this IronPDF rendering options tutorial.
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:
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
pdf.SaveAs("IronPDF PDF Library.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
pdf.SaveAs("IronPDF PDF Library.pdf");
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
pdf.SaveAs("IronPDF PDF Library.pdf")
The above code will create a PDF file of the given URL parameter 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.
URL to PDF Document
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.
9 .NET API products for your office documents