Skip to footer content
USING IRONPDF

ASP PDF Viewer (Developer Tutorial)

This article will discuss how you can use the 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 the 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 PDFs 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 you can automatically open a PDF viewer on the server using C# code after creating a PDF. Below is the source code example of viewing a PDF in the default PDF viewer using the Process.Start() method.

using IronPdf;
using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        // Create an instance of ChromePdfRenderer 
        var renderer = new IronPdf.ChromePdfRenderer();

        // Render a simple HTML string to a PDF
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1><p>IronPDF Demo</p>");

        // Define the output path for the PDF file
        var outputPath = "ChromePdfRenderer.pdf";

        // Save the PDF to the specified path
        pdf.SaveAs(outputPath);

        // Output the path to the console
        Console.WriteLine("PDF saved to: " + outputPath);

        // Start the default PDF viewer with the created PDF
        Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = outputPath });
    }
}
using IronPdf;
using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        // Create an instance of ChromePdfRenderer 
        var renderer = new IronPdf.ChromePdfRenderer();

        // Render a simple HTML string to a PDF
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1><p>IronPDF Demo</p>");

        // Define the output path for the PDF file
        var outputPath = "ChromePdfRenderer.pdf";

        // Save the PDF to the specified path
        pdf.SaveAs(outputPath);

        // Output the path to the console
        Console.WriteLine("PDF saved to: " + outputPath);

        // Start the default PDF viewer with the created PDF
        Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = outputPath });
    }
}
Imports IronPdf
Imports System
Imports System.Diagnostics

Friend Class Program
	Shared Sub Main()
		' Create an instance of ChromePdfRenderer 
		Dim renderer = New IronPdf.ChromePdfRenderer()

		' Render a simple HTML string to a PDF
		Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1><p>IronPDF Demo</p>")

		' Define the output path for the PDF file
		Dim outputPath = "ChromePdfRenderer.pdf"

		' Save the PDF to the specified path
		pdf.SaveAs(outputPath)

		' Output the path to the console
		Console.WriteLine("PDF saved to: " & outputPath)

		' Start the default PDF viewer with the created PDF
		Process.Start(New ProcessStartInfo With {
			.UseShellExecute = True,
			.FileName = outputPath
		})
	End Sub
End Class
$vbLabelText   $csharpLabel

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 PDFViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // Create an instance of ChromePdfRenderer
            var renderer = new IronPdf.ChromePdfRenderer();

            // Render a simple HTML string to a PDF
            using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1><p>IronPDF Demo</p>");

            // Extract all the text content from the PDF
            string allText = pdf.ExtractAllText();

            // Set the extracted text in the label on the Windows Form
            label1.Text = allText;
        }
    }
}
using System.Windows.Forms;
using IronPdf;

namespace PDFViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // Create an instance of ChromePdfRenderer
            var renderer = new IronPdf.ChromePdfRenderer();

            // Render a simple HTML string to a PDF
            using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1><p>IronPDF Demo</p>");

            // Extract all the text content from the PDF
            string allText = pdf.ExtractAllText();

            // Set the extracted text in the label on the Windows Form
            label1.Text = allText;
        }
    }
}
Imports System.Windows.Forms
Imports IronPdf

Namespace PDFViewer
	Partial Public Class Form1
		Inherits Form

		Public Sub New()
			InitializeComponent()

			' Create an instance of ChromePdfRenderer
			Dim renderer = New IronPdf.ChromePdfRenderer()

			' Render a simple HTML string to a PDF
			Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1><p>IronPDF Demo</p>")

			' Extract all the text content from the PDF
			Dim allText As String = pdf.ExtractAllText()

			' Set the extracted text in the label on the Windows Form
			label1.Text = allText
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

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 or 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 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 separately. This can significantly enhance the user experience. 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 ASP.NET PDF Viewer Documentation.

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.

Frequently Asked Questions

What is a powerful library for generating, editing, and processing PDF files in ASP.NET applications?

IronPDF is a powerful and flexible library for generating, editing, and processing PDF files in ASP.NET applications. It allows developers to generate PDF files from HTML, CSS, JavaScript, and images, as well as extract text and images from existing PDF files. IronPDF integrates seamlessly with ASP.NET applications and supports a wide range of output options.

What are the prerequisites for using a PDF processing library in an ASP.NET application?

To use IronPDF in an ASP.NET application, you need to have .NET Framework version 4.0 or higher, install the IronPDF NuGet package, and have basic knowledge of ASP.NET.

How do I install a PDF library using Visual Studio NuGet packages?

You can install IronPDF through the NuGet Package Manager in Visual Studio. Open the manager, search for IronPDF in the Browse tab, select it, and proceed with the installation.

How can I view a PDF file in my default PDF reader using a C# library?

You can use the Process.Start() method in C# to open a PDF file in the default PDF reader after it has been created using IronPDF.

Can a PDF library be used to view PDFs in Windows Forms applications?

Yes, IronPDF can be used to view PDF documents in Windows Forms applications by extracting text from the PDF and setting it in a label or other control within the form.

What are some output options supported by a PDF processing tool?

IronPDF supports a wide range of output options, including direct output to the browser, saving to disk, and sending PDF files as email attachments.

How does a PDF library enhance the user experience in ASP.NET applications?

IronPDF allows end-users to view PDF files directly on a web page without requiring them to download and open the file separately, thereby significantly enhancing the user experience.

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.