ASP PDF Viewer (Developer Tutorial)

ASP (Active Server Pages) is a web application framework developed by Microsoft to create dynamic HTTP web pages and web applications. One common need for web applications is to display documents, such as PDFs. PDF document (Portable Document Format) is a popular file format for documents that can be easily viewed and shared across different platforms and devices. ASP provides various ways to display these files through a PDF viewer control. An ASP PDF viewer control allows web developers to display PDF files directly on a web page, without requiring users to download and open the file separately. This can provide several advantages to both the web developers and the end-users. In this article, we will discuss how you can use C# ASP.NET programming language to view and save PDF file 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 New ASP.NET Core Project

In order 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 the purpose of this tutorial, we will be using the Console Application template.

ASP PDF Viewer (Developer Tutorial): Figure 2 - 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 3 - 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 4 - 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 5 - NuGet Package Manager

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

ASP PDF Viewer (Developer Tutorial): Figure 6 - 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 -Version 2023.3.2

Now the package will download/install to the current project and will be ready to use.

ASP PDF Viewer (Developer Tutorial): Figure 7 - 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 PDF file in your default PDF Reader.
  2. Creating form using C# and view PDF 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 server after creating a PDF. Below is the source code example of viewing PDF in default PDF viewer using Process.Start() method.


    using IronPdf;
    using System;
    using System.Diagnostics;

    var Render = new IronPdf.ChromePdfRenderer();
    //HTML string
    var PDF = Render.RenderHtmlAsPdf("Hello IronPDF
    IronPDF 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 Render = new IronPdf.ChromePdfRenderer();
    //HTML string
    var PDF = Render.RenderHtmlAsPdf("Hello IronPDF
    IronPDF Demo");
    var OutputPath = "ChromePdfRenderer.pdf";
    PDF.SaveAs(OutputPath);
    Console.WriteLine(OutputPath);
    Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = OutputPath });
Imports IronPdf
	Imports System
	Imports System.Diagnostics

	Private Render = New IronPdf.ChromePdfRenderer()
	'HTML string
	Private PDF = Render.RenderHtmlAsPdf("Hello IronPDF 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 8 - Browser Output

5.2. Viewing PDF in Windows Form

Using IronPDF, you can easily view your PDF documents in Windows form. First, create a new Windows form app project. Then add a label in 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 form.

ASP PDF Viewer (Developer Tutorial): Figure 9 - Windows Form

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/viewer, IronOCR for Optical Character Recognition, and IronBarcode for generating barcodes within .NET applications.