Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This article will discuss how you can use C# ASP.NET programming language to view and save PDF files with the help of IronPDF.
Process.Start
methodIronPDF 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.
To use IronPDF for ASP.NET to view PDF files, there are a few prerequisites that need to be met:
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.
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.
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.
Program.cs
Lastly, you can integrate the IronPDF library into your project to test the code.
The IronPDF library can be downloaded and installed in many different ways but today we will discuss only two of these.
These are:
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.
NuGet Package Manager
Write IronPDF in the search bar then select the appropriate version and click on Install.
IronPDF
Many people prefer to install packages using the command line interface. To install IronPDF using the command line, follow these steps:
Install-Package IronPdf
Now the package will download/install to the current project and will be ready to use.
IronPDF Installation
There are many ways to view PDF using IronPDF but here we will discuss two of these.
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
})
Browser Output
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
Now, your PDF file will be created and shown in the Windows Forms.
Windows Forms
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.
9 .NET API products for your office documents