Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This tutorial will demonstrate how to efficiently create and edit PDF files using the IronPDF C# library.
IronPDF is a powerful PDF library that can do almost anything a browser can. The .NET library for developers makes it easy to create, read, and manipulate PDF documents. IronPDF uses the Chrome engine to convert documents from HTML to PDF. Among other web components, IronPDF supports HTML, ASPX, Razor HTML, and MVC View. IronPDF supports Microsoft .NET Applications (both ASP.NET Core Web Applications and traditional Windows Applications). IronPDF can also be used to make visually pleasing PDF documents.
Open the Visual Studio and go to the File menu. Select "new project", and then select "ASP .NET Core Web App" as a starting template to generate PDF documents.
Create a new project in Visual Studio
Enter the project name and select the file path in the appropriate text box. Then, click the Create button and select the required .NET Framework, as in the screenshot below.
Configure the project within Visual Studio
Then, select the required .NET Famework and click the Create option.
Select .NET Framework
The Visual Studio project will now generate the structure for the selected application. Since this example are using ASP.NET MVC, it is necessary to create a Controller to write the code or use the existing Controller where you can enter the code and build/run the application.
Create a Controller for ASP.NET MVC Application
The next section shows how to add the library to test the code.
The IronPDF Library can be downloaded and installed in four ways.
These are:
The Visual Studio software provides the NuGet Package Manager option to install the package directly to the solution. The below screenshot shows how to open the NuGet Package Manager.
Navigate to NuGet Package Manager
It provides the search box to show the list of packages from the NuGet website. In the NuGet Package Manager, search for the keyword "IronPDF", as in the screenshot below.
Install IronPdf
package in NuGet Package Manager UI
In the above image, it shows the list of the related search items. Select the required option to install the package to the solution.
In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Console
Enter the following line in the Package Manager Console tab:
Install-Package IronPdf
Now the package will download/install to the current project and be ready to use.
Install the package in the Package Manager Console
The third way is to download the NuGet package directly from the website.
Click the link to download the Zip file package directly from the website. Once downloaded, follow the steps below to add the package to the project.
There are three ways to generate a PDF file from HTML content.
IronPDF makes it easy to create a PDF document by generating an HTML file from a URL and converting it to a PDF document. The HTML data will be downloaded using IronPDF's built-in Chrome browser.
The following steps make it easy to create PDF files:
public class PdfController : Controller
{
public IActionResult GeneratePdf()
{
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/");
return File(pdf.BinaryData, "application/pdf", "output.pdf");
}
}
public class PdfController : Controller
{
public IActionResult GeneratePdf()
{
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/");
return File(pdf.BinaryData, "application/pdf", "output.pdf");
}
}
Public Class PdfController
Inherits Controller
Public Function GeneratePdf() As IActionResult
Dim renderer = New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.google.co.in/")
Return File(pdf.BinaryData, "application/pdf", "output.pdf")
End Function
End Class
In the above code, the PDF creation process is done.
HTML strings can also be transformed into PDF files with the help of IronPDF. The sample code for transforming HTML strings into documents is shown below. It also allows you to convert any HTML element into a PDF file.
using var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello world!!</h1>");
pdf.SaveAs("output.pdf");
using var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello world!!</h1>");
pdf.SaveAs("output.pdf");
Dim pdf = (New IronPdf.ChromePdfRenderer()).RenderHtmlAsPdf("<h1>Hello world!!</h1>")
pdf.SaveAs("output.pdf")
The accompanying example shows how to translate HTML with RenderHtmlAsPdf
. In addition, the function which helps to convert HTML pages to a string can take any number of HTML codes. Additionally, the SaveAs
function can be used to save the document to the server location.
This section will show how to transform HTML files into PDF files with the help of IronPDF. The sample code for transforming HTML into documents is shown below. It also allows you to convert any HTML element into a PDF file.
public class PdfController : Controller
{
public IActionResult GeneratePdf()
{
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("demo.html");
return File(pdf.BinaryData, "application/pdf", "output.pdf");
}
}
public class PdfController : Controller
{
public IActionResult GeneratePdf()
{
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("demo.html");
return File(pdf.BinaryData, "application/pdf", "output.pdf");
}
}
Public Class PdfController
Inherits Controller
Public Function GeneratePdf() As IActionResult
Dim renderer = New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("demo.html")
Return File(pdf.BinaryData, "application/pdf", "output.pdf")
End Function
End Class
The accompanying example shows how to translate HTML files with RenderHtmlFileAsPdf
. In addition, the function that helps to convert HTML pages from the file into a string can take any number of HTML codes. The above code will return data to download the PDF file through the click of a button.
Below is the sample page created using the ASP.NET MVC.
The ASP.NET application to generate PDF file
Below is the created PDF document's snapshot.
The result PDF file generated from HTML files
Finally, when producing HTML, IronPDF takes the user's browser preferences into account. IronPDF is capable of producing HTML at a faster rate. IronPDF includes royalty-free redistribution protection. The IronPDF is recommended because of its high-performance levels and the vast range of capabilities available to developers working with the Portable Document Format. IronPDF also offers excellent assistance and documentation to guarantee that customers can take advantage of all the program's remarkable features.
IronPDF offers a free trial key, or you can currently buy five products from Iron Software for the price of just two. Visit the pricing page to learn more about pricing.
9 .NET API products for your office documents