USING IRONPDF

ASP PDF Viewer (Developer Tutorial)

Updated April 19, 2023
Share:

This article will discuss how you can use C# ASP.NET programming language to view and save PDF files with the help of IronPDF.

1. IronPDF For ASP.NET

IronPDF is a powerful and flexible library for generating, editing, and processing PDF files in ASP.NET applications. It allows developers to easily generate PDF files from HTML, CSS, JavaScript and images, as well as extract text and images from existing PDF files. IronPDF is built on top of Chromium and supports a wide range of HTML and CSS features, making it easy to create high-quality PDF documents that match the look and feel of your Web Application. It integrates seamlessly with ASP.NET applications and can be easily customized to meet specific requirements. IronPDF also supports a wide range of output options, including direct output to the browser, saving to disk, and sending PDF files as email attachments.

2. Prerequisites

To use IronPDF for ASP.NET to view PDF files, there are a few prerequisites that need to be met:

  1. .NET Framework: IronPDF requires the .NET Framework version 4.0 or higher to be installed on the server. If you are using a version of Visual Studio that supports Core, you can also use IronPDF with .NET Core.
  2. IronPDF NuGet Package: You need to install the IronPDF NuGet package in your ASP.NET solution. You can install the package through Visual Studio's NuGet Package Manager or by using the Package Manager Console.
  3. Basic ASP.NET Knowledge

3. Creating a New ASP.NET Core Project

To use the IronPDF library for viewing in your .NET application, you need to create a new project in Visual Studio. You can use any version, but it is recommended to use the latest one available. Depending on your requirements, you can choose from different project templates, such as Windows Forms. For this tutorial, a Console Application template will be used for simplicity.

ASP PDF Viewer (Developer Tutorial), Figure 1: Console Application Console Application

Once you have selected the appropriate project type, you can provide a name for the project and choose a location for it. Select the desired framework, such as .NET Core for the project.

ASP PDF Viewer (Developer Tutorial), Figure 2: Project Configuration Project Configuration

After the project solution has been created, you will be able to access the Program.cs file where you can write your logic within Main function and construct/run the application.

ASP PDF Viewer (Developer Tutorial), Figure 3: Program.cs Program.cs

Lastly, you can integrate the IronPDF library into your project to test the code.

4. Install IronPDF

The IronPDF library can be downloaded and installed in many different ways but today we will discuss only two of these.

These are:

  • Using Visual Studio NuGet packages
  • Using the Visual Studio Command-Line

4.1 Using Visual Studio NuGet packages

To install the IronPDF library, you can use the NuGet Package Manager in Visual Studio. Open the NuGet Package Manager and search for IronPDF in the Browse tab. Once you have located IronPDF in the search results, select it and proceed with the installation. After the installation is complete, you can begin using the IronPDF library in your project.

The below screenshot shows how we can open the NuGet Package Manager in Visual Studio.

ASP PDF Viewer (Developer Tutorial), Figure 4: NuGet Package Manager NuGet Package Manager

Write IronPDF in the search bar then select the appropriate version and click on Install.

ASP PDF Viewer (Developer Tutorial), Figure 5: IronPDF IronPDF

4.2 Using the Visual Studio Command-Line

Many people prefer to install packages using the command line interface. To install IronPDF using the command line, follow these steps:

  • 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 will be ready to use.

ASP PDF Viewer (Developer Tutorial), Figure 6: IronPDF Installation IronPDF Installation

5. Viewing PDF file using IronPDF

There are many ways to view PDF using IronPDF but here we will discuss two of these.

  1. First is using code to open a PDF file in your default PDF Reader.
  2. Create a form using C# and view the PDF file in it.

5.1. Viewing PDF Document in your default PDF Reader

In this section, we will see how only using C# code you can automatically open PDF viewer control on the server after creating a PDF. Below is the source code example of viewing PDF in the default PDF viewer using Process.Start() method.

using IronPdf;
using System;
using System.Diagnostics;

var renderer = new IronPdf.ChromePdfRenderer();
//HTML string
var pdf = renderer.RenderHtmlAsPdf("Hello IronPDF\nIronPDF Demo");
var outputPath = "ChromePdfRenderer.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine(outputPath);
Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = outputPath });
using IronPdf;
using System;
using System.Diagnostics;

var renderer = new IronPdf.ChromePdfRenderer();
//HTML string
var pdf = renderer.RenderHtmlAsPdf("Hello IronPDF\nIronPDF Demo");
var outputPath = "ChromePdfRenderer.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine(outputPath);
Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = outputPath });
Imports Microsoft.VisualBasic
Imports IronPdf
Imports System
Imports System.Diagnostics

Private renderer = New IronPdf.ChromePdfRenderer()
'HTML string
Private pdf = renderer.RenderHtmlAsPdf("Hello IronPDF" & vbLf & "IronPDF Demo")
Private outputPath = "ChromePdfRenderer.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine(outputPath)
Process.Start(New ProcessStartInfo With {
	.UseShellExecute = True,
	.FileName = outputPath
})
VB   C#

ASP PDF Viewer (Developer Tutorial), Figure 7: Browser Output Browser Output

5.2. Viewing PDF in Windows Forms

Using IronPDF, you can easily view your PDF documents in Windows Forms. First, create a new Windows Forms app project. Then add a label in the design file and write the below source code in the Form1.cs file.

using System.Windows.Forms;
using IronPdf;

namespace PDF_viewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var renderer = new IronPdf.ChromePdfRenderer();
            using var pdf = renderer.RenderHtmlAsPdf("Hello IronPDF IronPDF Demo  ");
            string allText = pdf.ExtractAllText();
            label1.Text = allText;
        }
    }
}
using System.Windows.Forms;
using IronPdf;

namespace PDF_viewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var renderer = new IronPdf.ChromePdfRenderer();
            using var pdf = renderer.RenderHtmlAsPdf("Hello IronPDF IronPDF Demo  ");
            string allText = pdf.ExtractAllText();
            label1.Text = allText;
        }
    }
}
Imports System.Windows.Forms
Imports IronPdf

Namespace PDF_viewer
	Partial Public Class Form1
		Inherits Form

		Public Sub New()
			InitializeComponent()
			Dim renderer = New IronPdf.ChromePdfRenderer()
			Dim pdf = renderer.RenderHtmlAsPdf("Hello IronPDF IronPDF Demo  ")
			Dim allText As String = pdf.ExtractAllText()
			label1.Text = allText
		End Sub
	End Class
End Namespace
VB   C#

Now, your PDF file will be created and shown in the Windows Forms.

ASP PDF Viewer (Developer Tutorial), Figure 8: Windows Forms Windows Forms

6. Conclusion

IronPDF is a powerful and flexible library for creating, editing, and processing PDF files in ASP.NET applications. By integrating IronPDF into an ASP.NET project, developers can easily generate/upload PDF files from HTML, CSS, and images, as well as extract text and images from existing PDF files. Additionally, the system library supports a wide range of output options, including direct page output to the browser, saving to disk, and sending PDF files as email attachments. With the help of IronPDF, developers can create professional-looking PDF data that match the look and feel of their Web Application, and enable end-users to view PDF files directly on a web page, without requiring them to download and open the file control separately. Also, you can easily set page language. Overall, IronPDF is an Excellent tool for any developer looking to enhance their ASP.NET application's capabilities with PDF processing and viewing. For more details on PDF viewer, please visit the following link.

Iron Suite is a collection of powerful software tools designed to simplify and accelerate development tasks. It includes IronPDF for creating, reading, and manipulating PDF documents/viewers, IronOCR for Optical Character Recognition, and IronBarcode for generating barcodes within .NET applications.

< PREVIOUS
How to Convert PDF to JPG in .NET
NEXT >
PDF Converter .NET (Developer Tutorial)

Ready to get started? Version: 2024.6 just released

Start Free Trial Total downloads: 9,580,872
View Licenses >