Skip to footer content
USING IRONPDF

PDF Viewer for ASP.NET: How to Display PDFs in .NET 10

To implement a PDF viewer in ASP.NET Core, use IronPDF to generate PDFs from HTML, URLs, or Razor views. Serve them with proper headers for inline browser display, providing a smooth document viewing experience without external plugins or downloads.

Building a web application in .NET often requires displaying PDF documents directly in the browser. Whether it's invoices, reports, or interactive PDF forms, users expect a smooth document viewer experience without needing Adobe Acrobat Reader or other third-party browser tools.

In this tutorial, you'll learn how to implement a PDF viewer for ASP.NET and .NET Core using IronPDF. This reliable PDF viewer control allows developers to create, render, and display PDF files within .NET applications, providing a professional solution for handling business-critical documents. The approach described here works with .NET 10 and all earlier .NET Core versions.

How Does PDF Viewing Work in ASP.NET Core?

Modern browsers act as built-in PDF viewers. When you serve a PDF file with the correct MIME type (application/pdf), the browser automatically displays it inline. This means you don't need external plugins to view PDF documents or display PDF files. The key lies in generating high-quality PDFs and configuring the correct response headers.

IronPDF is a frequently updated .NET PDF library that excels at creating pixel-perfect PDF pages from HTML, Razor views, or existing documents. Its Chrome-based rendering engine ensures accurate CSS, JavaScript, and image support, giving users a viewing experience comparable to a desktop PDF viewer. You can explore the full list of capabilities on the IronPDF features page.

When a request hits your ASP.NET Core controller, the workflow is straightforward: generate (or load) a PDF using IronPDF, set the Content-Disposition response header to inline, specify the MIME type as application/pdf, and return the binary data. The browser handles rendering automatically -- no JavaScript PDF.js setup required, and no dependency on browser extensions.

Understanding this pattern early saves development time. Instead of integrating a complex JavaScript viewer library, you delegate the rendering work to the browser and use IronPDF purely for generation and manipulation on the server side. The ASP.NET Core documentation on file responses explains the underlying FileResult type used in these patterns.

How Do You Set Up an ASP.NET Core Project?

Start by creating a new ASP.NET Core MVC application. Open a terminal and run:

dotnet new mvc -n PdfViewerApp
cd PdfViewerApp
dotnet new mvc -n PdfViewerApp
cd PdfViewerApp
SHELL

This scaffolds a basic .NET application with MVC support. The MVC structure gives you controllers to handle PDF generation requests and views to build the front-end interface. A dedicated PdfController keeps PDF-related logic organized and easy to maintain as the application grows.

How Do You Install and Configure IronPDF?

Installing IronPDF takes just a few steps. Use either the NuGet Package Manager console in Visual Studio or the .NET CLI:

# Package Manager Console (Visual Studio)
Install-Package IronPdf

# .NET CLI
dotnet add package IronPdf
# Package Manager Console (Visual Studio)
Install-Package IronPdf

# .NET CLI
dotnet add package IronPdf
SHELL

Then configure the library in Program.cs:

using IronPdf;

// Set license key at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
using IronPdf;

// Set license key at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
$vbLabelText   $csharpLabel

Set up your license key in Program.cs before any PDF operations. A free trial license is available for development and evaluation. The IronPDF documentation provides additional configuration examples for different deployment environments, including Azure and Docker.

How Do You Generate PDFs for Viewing?

IronPDF lets you create PDF files from raw HTML strings, live web pages, or Razor views. The generated PDF document can then be displayed inline with just a few lines of C# code.

This approach avoids forcing a download, giving users the ability to view, print, search, and save PDFs directly inside the browser -- without any additional viewer component on the client side.

How Do You Create PDFs from HTML Strings?

The simplest approach converts an HTML string directly to PDF. Use this pattern to generate dynamic content like reports or invoices:

using IronPdf;

var renderer = new ChromePdfRenderer();

string html = @"
    <html>
    <head>
        <style>
            body { font-family: Arial; padding: 20px; }
            h1 { color: #333; }
        </style>
    </head>
    <body>
        <h1>Sample PDF Document</h1>
        <p>This PDF was generated using IronPDF in ASP.NET Core.</p>
    </body>
    </html>";

var pdf = renderer.RenderHtmlAsPdf(html);

// Return PDF to browser for inline viewing
return File(pdf.BinaryData, "application/pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

string html = @"
    <html>
    <head>
        <style>
            body { font-family: Arial; padding: 20px; }
            h1 { color: #333; }
        </style>
    </head>
    <body>
        <h1>Sample PDF Document</h1>
        <p>This PDF was generated using IronPDF in ASP.NET Core.</p>
    </body>
    </html>";

var pdf = renderer.RenderHtmlAsPdf(html);

// Return PDF to browser for inline viewing
return File(pdf.BinaryData, "application/pdf");
$vbLabelText   $csharpLabel

A ChromePdfRenderer is created, which uses the Chromium engine for accurate rendering. The HTML (with inline CSS) is passed to RenderHtmlAsPdf, producing a PdfDocument. Returning the file with the application/pdf MIME type ensures the browser displays it inline. For a deeper look at this conversion method, see the HTML string to PDF guide.

How Do You Generate PDFs from URLs?

Converting existing web pages into PDFs is equally straightforward. This is useful for archiving live content or generating snapshots of reports published as web pages:

using IronPdf;

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.JavaScript(3000);
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

var pdf = renderer.RenderUrlAsPdf("https://example.com/report");
Response.Headers.Add("Content-Disposition", "inline; filename=webpage.pdf");

return File(pdf.BinaryData, "application/pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.JavaScript(3000);
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

var pdf = renderer.RenderUrlAsPdf("https://example.com/report");
Response.Headers.Add("Content-Disposition", "inline; filename=webpage.pdf");

return File(pdf.BinaryData, "application/pdf");
$vbLabelText   $csharpLabel

The RenderUrlAsPdf method fetches the page, applies styles and scripts, and outputs a polished PDF. Setting the Content-Disposition header to inline makes the file open in the browser's PDF viewer. The JavaScript rendering options ensure dynamic content loads properly before capture.

PDF viewer web application displaying IronPDF for .NET documentation with Generate from HTML, Generate from URL, and Print buttons at the top

How Can You Convert Razor Views to PDF?

Razor views are ideal templates for structured documents like invoices, because the same template can serve both the web page and the PDF output. Render the view to an HTML string, then pass it to IronPDF:

using IronPdf;

// Render the Razor view to an HTML string first
var htmlContent = await RenderViewToString("Invoice", invoiceModel);

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);

return File(pdf.BinaryData, "application/pdf");
using IronPdf;

// Render the Razor view to an HTML string first
var htmlContent = await RenderViewToString("Invoice", invoiceModel);

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);

return File(pdf.BinaryData, "application/pdf");
$vbLabelText   $csharpLabel

The view is first rendered into an HTML string using a helper method, then converted using RenderHtmlAsPdf. This approach lets you reuse Razor templates for both web display and PDF generation, ensuring the output stays consistent across formats. The HTML to PDF how-to guide covers additional Razor integration patterns.

How Do You Display PDFs Inline in the Browser?

The key to displaying PDFs inline (rather than triggering a download) lies in setting the correct response headers. Modern browsers support inline PDF viewing when the content type and disposition are configured properly.

Setting Content-Disposition: inline tells the browser to render the PDF directly, while Content-Disposition: attachment would prompt a download dialog. The distinction is a single header value change, but it significantly affects the user experience.

You can also enhance displayed documents with headers and footers for page numbering and branding, or add custom watermarks to mark documents as drafts or confidential.

How Can You Enable Dynamic PDF Loading?

For applications that need to switch between multiple documents without a full page refresh, use an iframe combined with controller endpoints:

using IronPdf;
using Microsoft.AspNetCore.Mvc;

// Controller action to list available PDFs
[HttpGet]
public IActionResult GetPdfList()
{
    var pdfs = new List<object>
    {
        new { id = 1, name = "Report 1" },
        new { id = 2, name = "Report 2" }
    };
    return Json(pdfs);
}

// Controller action to generate and return a specific PDF
[HttpGet]
public IActionResult GetPdf(int id)
{
    var renderer = new ChromePdfRenderer();
    string html = $"<h1>Report {id}</h1><p>Content for report {id}.</p>";
    var pdf = renderer.RenderHtmlAsPdf(html);
    Response.Headers.Add("Content-Disposition", $"inline; filename=report-{id}.pdf");
    return File(pdf.BinaryData, "application/pdf");
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;

// Controller action to list available PDFs
[HttpGet]
public IActionResult GetPdfList()
{
    var pdfs = new List<object>
    {
        new { id = 1, name = "Report 1" },
        new { id = 2, name = "Report 2" }
    };
    return Json(pdfs);
}

// Controller action to generate and return a specific PDF
[HttpGet]
public IActionResult GetPdf(int id)
{
    var renderer = new ChromePdfRenderer();
    string html = $"<h1>Report {id}</h1><p>Content for report {id}.</p>";
    var pdf = renderer.RenderHtmlAsPdf(html);
    Response.Headers.Add("Content-Disposition", $"inline; filename=report-{id}.pdf");
    return File(pdf.BinaryData, "application/pdf");
}
$vbLabelText   $csharpLabel

On the client side, update the iframe source with a short JavaScript snippet in your Razor view to load different PDFs without a page reload. The controller generates PDFs on demand, keeping the response size predictable. For large documents, combine this pattern with IronPDF's merge and split functionality to serve documents in sections.

Screenshot of PdfViewerApp showing a PDF viewer displaying 'Hello World' text with navigation controls and action buttons for Generate From HTML, Generate From URL, and Print

How Do You Handle Deployment and Performance?

IronPDF works across ASP.NET, ASP.NET Core, and Blazor Server projects. You can host on Windows Server, deploy to Azure, or containerize with Docker. Since it fully supports .NET 10 alongside earlier versions, it integrates into modern and legacy applications alike.

How Do You Deploy to Azure?

When deploying to Azure App Service, IronPDF works with minimal additional configuration. Ensure your App Service plan is at least the B1 tier for optimal performance. IronPDF automatically handles the Chrome rendering engine deployment.

For containerized deployments on Linux, add the required system dependencies to your Dockerfile:

RUN apt-get update && apt-get install -y libgdiplus
RUN apt-get update && apt-get install -y libgdiplus
SHELL

The IronPDF documentation covers platform-specific Linux requirements in detail. Consider using IronPDF Slim for reduced container image sizes when the full Chrome rendering engine is not required.

What Are the Key Performance Considerations?

Performance in a PDF-serving application depends on how frequently PDFs are generated and how large they are. The following practices apply to most production deployments:

  • Cache generated PDFs when the underlying content does not change frequently, using memory streams or a distributed cache
  • Use async controller actions to avoid blocking threads during PDF generation
  • Set appropriate rendering timeouts for complex HTML pages with heavy JavaScript
  • Apply watermarks and compression to reduce file sizes before serving
  • Enable PDF to image conversion for generating preview thumbnails rather than loading full PDFs in document listings
  • Use text extraction to build server-side search indexes instead of relying on the browser's built-in PDF search

How Do You Troubleshoot Common PDF Display Issues?

Why Is the PDF Downloading Instead of Displaying?

If PDFs download instead of displaying inline, verify the response headers are set correctly. Check that the MIME type is exactly application/pdf and that Content-Disposition is set to inline, not attachment:

Response.Headers.Add("Content-Disposition", "inline; filename=document.pdf");
return File(pdf.BinaryData, "application/pdf");
Response.Headers.Add("Content-Disposition", "inline; filename=document.pdf");
return File(pdf.BinaryData, "application/pdf");
$vbLabelText   $csharpLabel

Some proxies and load balancers strip or modify response headers -- confirm the headers reach the browser using developer tools. For cross-origin scenarios, add CORS headers in Program.cs rather than on individual responses to keep the configuration centralized. If the PDFs contain sensitive data, apply PDF signing and password protection rather than relying solely on CORS restrictions.

How Do You Handle Large PDF Files?

For large documents, streaming reduces memory pressure on the server. Use a FileStreamResult instead of returning the raw byte array:

using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(largeHtmlContent);

var stream = new MemoryStream(pdf.BinaryData);
return new FileStreamResult(stream, "application/pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(largeHtmlContent);

var stream = new MemoryStream(pdf.BinaryData);
return new FileStreamResult(stream, "application/pdf");
$vbLabelText   $csharpLabel

For very large documents, consider splitting them into sections using IronPDF's merge and split functionality and implementing pagination in the user interface. This keeps individual PDF responses small and fast to load. Microsoft's ASP.NET Core large file guidance also covers buffering strategies relevant to PDF delivery.

How Do You Go Further with IronPDF?

Building a PDF viewer in ASP.NET Core does not require complex third-party viewer libraries. By combining IronPDF's server-side rendering engine with the browser's native PDF support, you get a professional document viewing solution that scales well and requires minimal client-side setup. The IronPDF home page provides an overview of the full library and getting started resources.

From here, you can extend the implementation in several directions:

For the complete API reference, visit the IronPDF documentation. To start building today, get a free trial of IronPDF -- no credit card required.

Get stated with IronPDF now.
green arrow pointer

Frequently Asked Questions

What is the best way to display PDF documents in an ASP.NET application?

Using IronPDF allows developers to easily render PDF documents directly in the browser within an ASP.NET application, providing a seamless user experience without the need for third-party tools like Adobe Acrobat Reader.

Can IronPDF be used to enhance PDF viewing in web applications?

Yes, IronPDF is designed to enhance PDF viewing by allowing smooth integration into web applications, ensuring that users can view PDF documents with ease and efficiency.

Do I need additional tools to view PDFs when using IronPDF in ASP.NET?

No, IronPDF eliminates the need for additional tools like Adobe Acrobat Reader, offering a built-in solution for viewing PDFs directly in ASP.NET applications.

How can I implement a PDF viewer in my .NET web application?

By integrating IronPDF into your .NET web application, you can implement a powerful PDF viewer that supports various PDF functionalities and offers a user-friendly interface.

Why should I use IronPDF for PDF viewing in ASP.NET?

IronPDF provides a reliable and efficient solution for PDF viewing in ASP.NET applications, enabling developers to offer users a seamless experience without relying on external plugins.

Is it possible to display interactive PDF forms using IronPDF?

Yes, IronPDF supports the display of interactive PDF forms, allowing users to fill out and interact with PDF documents directly within the browser.

What types of PDF documents can be viewed using IronPDF?

IronPDF can handle various types of PDF documents, including invoices, reports, and interactive forms, making it a versatile tool for any ASP.NET application.

Does IronPDF support .NET 10 for PDF generation and viewing?

Yes. IronPDF fully supports .NET 10, along with earlier versions like .NET 9, 8, 7, 6, and .NET Core and Framework. This means you can use IronPDF in modern .NET 10 ASP.NET or Blazor applications to generate, serve, and display PDFs inline in the browser. (ironpdf.com)

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me