How to Display, Save, and Print PDFs in an ASP.NET Core Viewer
How to Display, Save, and Print PDFs in an ASP.NET Core Viewer
Displaying PDF documents directly in web browsers has become an essential requirement for modern ASP.NET Core web applications. Whether you're generating invoices, reports, or contracts, users expect seamless PDF viewing without needing to download PDF files or install Adobe Acrobat Reader or other plugins. This tutorial demonstrates how IronPDF simplifies PDF file display, saving, and printing in your ASP.NET Core PDF viewer through its powerful Chrome-based rendering engine.
How Do Browsers Handle PDF Viewing in ASP.NET Core?
Modern browsers include built-in PDF viewers that activate when they receive a PDF file with the correct MIME type (application/pdf). When your ASP.NET Core web application returns a PDF document with appropriate headers, the browser automatically displays it inline. This eliminates the need for external plugins, Adobe Acrobat Reader, or complex JavaScript libraries. According to MDN Web Docs, proper header configuration is essential for controlling how browsers handle file downloads and displays.
IronPDF leverages this browser capability by generating high-quality PDF files server-side using its ChromePdfRenderer class. The renderer uses a complete Chrome engine under the hood, ensuring your PDF documents display exactly as intended with full support for modern CSS, JavaScript, digital signatures, and web fonts. Unlike simple document viewers, IronPDF provides complete control over PDF processing and rendering.
What Tools Do You Need to Display/View PDF Files in ASP.NET Core?
Setting up IronPDF in your ASP.NET Core PDF viewer project takes just a few steps. First, create a new project in Visual Studio or via the command line. Open Visual Studio and select the ASP.NET Core Web Application project template:
dotnet new mvc -n PdfViewerApp
cd PdfViewerAppdotnet new mvc -n PdfViewerApp
cd PdfViewerAppInstalling the IronPDF .NET Package
Install IronPDF via NuGet Package Manager in your .NET project:
Install-Package IronPdf
Or in Solution Explorer, right-click on your project and select "Manage NuGet Packages." Choose the appropriate package source and search for IronPDF.
That's all the setup required. IronPDF works seamlessly with ASP.NET Core 3.1 and later (long-term support versions), including .NET 6, 7, and 8. The library is frequently updated to ensure compatibility with the latest frameworks. For detailed installation instructions and additional information, visit the IronPDF installation guide. The package includes all necessary components for PDF generation, editing, and processing.
How Can You Display PDF Files in the Browser Using ASP.NET Core?
Creating and displaying PDF files in the browser requires just a few lines of code. Here's a complete controller action that generates a PDF document from HTML and displays it inline. This code snippet demonstrates the core functionality:
using IronPdf;
using Microsoft.AspNetCore.Mvc;
public class PdfController : Controller
{
public IActionResult ViewPdf()
{
var renderer = new ChromePdfRenderer();
// Configure rendering options for the PDF viewer
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderingOptions.EnableJavaScript = true;
// Generate PDF from HTML string
var html = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
h1 { color: #2c3e50; }
.content { line-height: 1.6; width: 100%; }
</style>
</head>
<body>
<h1>Invoice #12345</h1>
<div class='content'>
<p>Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>
<p>Thank you for your business!</p>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Return PDF for inline viewing in the browser
return File(pdf.BinaryData, "application/pdf");
}
}using IronPdf;
using Microsoft.AspNetCore.Mvc;
public class PdfController : Controller
{
public IActionResult ViewPdf()
{
var renderer = new ChromePdfRenderer();
// Configure rendering options for the PDF viewer
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderingOptions.EnableJavaScript = true;
// Generate PDF from HTML string
var html = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
h1 { color: #2c3e50; }
.content { line-height: 1.6; width: 100%; }
</style>
</head>
<body>
<h1>Invoice #12345</h1>
<div class='content'>
<p>Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>
<p>Thank you for your business!</p>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Return PDF for inline viewing in the browser
return File(pdf.BinaryData, "application/pdf");
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comThe above code creates a ChromePdfRenderer instance and configures it to include background colors and convert HTML forms to PDF forms. The RenderHtmlAsPdf method transforms the HTML string into a PDF file. The following code shows how returning the PDF with the application/pdf MIME type tells the browser to display it inline rather than downloading it. This server-side approach ensures consistent rendering across all browsers and platforms.
Output

For existing HTML files or Razor pages, you can use alternative rendering methods to view PDF content:
// Render from URL - useful for complex pages
var pdf = renderer.RenderUrlAsPdf("https://example.com/invoice");
// Render from HTML file in the same location
var pdf = renderer.RenderHtmlFileAsPdf("Views/Invoice.html");
// Render from wwwroot folder
var pdf = renderer.RenderHtmlFileAsPdf("wwwroot/templates/report.html");// Render from URL - useful for complex pages
var pdf = renderer.RenderUrlAsPdf("https://example.com/invoice");
// Render from HTML file in the same location
var pdf = renderer.RenderHtmlFileAsPdf("Views/Invoice.html");
// Render from wwwroot folder
var pdf = renderer.RenderHtmlFileAsPdf("wwwroot/templates/report.html");IRON VB CONVERTER ERROR developers@ironsoftware.comThese methods provide flexibility in how you source your HTML content while maintaining the same high-quality PDF rendering output. You can also load existing PDF documents, edit PDF files, and even work with Word (DOCX files) and Excel formats using IronPDF's comprehensive features. Learn more about HTML to PDF conversion options in the documentation. For advanced processing and editing capabilities, refer to the API reference.
How Do Users Save PDF Documents from the Browser?
To enable users to download PDF files instead of viewing them inline, modify the Content-Disposition header. This feature is essential for web applications where users need to save documents for offline access:
public IActionResult DownloadPdf()
{
var renderer = new ChromePdfRenderer();
// Create PDF with CSS styling and images
var html = @"<h1>Download Me</h1>
<img src='logo.png' width='100' />";
var pdf = renderer.RenderHtmlAsPdf(html, @"wwwroot/images");
// Force download with custom filename
return File(pdf.BinaryData, "application/pdf", "invoice-2024.pdf");
}public IActionResult DownloadPdf()
{
var renderer = new ChromePdfRenderer();
// Create PDF with CSS styling and images
var html = @"<h1>Download Me</h1>
<img src='logo.png' width='100' />";
var pdf = renderer.RenderHtmlAsPdf(html, @"wwwroot/images");
// Force download with custom filename
return File(pdf.BinaryData, "application/pdf", "invoice-2024.pdf");
}IRON VB CONVERTER ERROR developers@ironsoftware.comAdding the filename parameter automatically sets the Content-Disposition header to "attachment," prompting the browser to download the file. Users can also save PDF files displayed inline using their browser's built-in save functionality, accessible through Ctrl+S or the browser's PDF viewer toolbar. The default behavior allows users to choose their preferred folder location.
Output

For better memory efficiency when handling large PDF documents, use streams:
public IActionResult StreamPdf()
{
var renderer = new ChromePdfRenderer();
// Load and process HTML with images
var html = "<h1>Streamed Content</h1>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Stream the PDF file to the browser
var stream = pdf.Stream;
stream.Position = 0;
return File(stream, "application/pdf", "document.pdf");
}public IActionResult StreamPdf()
{
var renderer = new ChromePdfRenderer();
// Load and process HTML with images
var html = "<h1>Streamed Content</h1>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Stream the PDF file to the browser
var stream = pdf.Stream;
stream.Position = 0;
return File(stream, "application/pdf", "document.pdf");
}IRON VB CONVERTER ERROR developers@ironsoftware.comThis approach reduces memory consumption by streaming the PDF file directly to the response without creating intermediate byte arrays. The above code demonstrates efficient file handling for large documents. You can also load existing PDF files from the wwwroot folder or other locations, edit them, and stream the modified versions. For more advanced PDF document manipulation and image processing, explore the PdfDocument API reference. The component supports various editing operations including text selection, form filling, and adding digital signatures.
Can Users Print PDF Documents Directly from ASP.NET Core Web Applications?
IronPDF optimizes PDF files for printing by configuring the appropriate CSS media type and page settings. This feature ensures professional output whether users print to physical printers or save as PDF:
public IActionResult PrintablePdf()
{
var renderer = new ChromePdfRenderer();
// Configure printing options for the PDF viewer
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;
renderer.RenderingOptions.MarginLeft = 25;
renderer.RenderingOptions.MarginRight = 25;
// Load HTML with print-specific CSS
var html = @"<h1>Print-Optimized Document</h1>
<p>This document is optimized for printing.</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Return the PDF file for viewing and printing
return File(pdf.BinaryData, "application/pdf");
}public IActionResult PrintablePdf()
{
var renderer = new ChromePdfRenderer();
// Configure printing options for the PDF viewer
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;
renderer.RenderingOptions.MarginLeft = 25;
renderer.RenderingOptions.MarginRight = 25;
// Load HTML with print-specific CSS
var html = @"<h1>Print-Optimized Document</h1>
<p>This document is optimized for printing.</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Return the PDF file for viewing and printing
return File(pdf.BinaryData, "application/pdf");
}IRON VB CONVERTER ERROR developers@ironsoftware.comSetting CssMediaType to Print applies print-specific CSS styles, ensuring the PDF document looks correct when printed. The margin settings provide proper spacing for physical paper. The following code shows how users can print PDF files directly from their browser's PDF viewer using the standard print dialog, maintaining full control over printer selection and settings. Learn more about PDF rendering options to fine-tune your output. The core PDF viewer component handles all printing details automatically.

Cross-Platform and Container Support
IronPDF runs seamlessly across Windows, Linux, macOS, Docker containers, and cloud platforms like Azure and AWS. This cross-platform compatibility ensures your ASP.NET Core PDF viewer solution works consistently regardless of deployment environment. The library handles platform-specific rendering details internally, so the same code works everywhere without modification.

The server-side processing ensures consistent PDF generation across all platforms. Whether deployed on Windows servers or Linux containers, the component maintains the same rendering quality. The library automatically manages path differences between operating systems, so files in the wwwroot folder or other locations are handled correctly. For containerized deployments, check the Docker deployment guide. The package includes all necessary dependencies for each platform, and setup requires no additional configuration beyond standard ASP.NET Core requirements.
Get started with a free trial and transform your document viewer capabilities today.
Summary
IronPDF transforms PDF handling in ASP.NET Core web applications by combining server-side generation with browser-native viewing. With just a few lines of code, you can create professional PDF documents from HTML, display PDF files inline, enable downloads, and optimize for printing. The Chrome-based rendering engine ensures pixel-perfect accuracy across all platforms, eliminating the need for Adobe Acrobat Reader or other third-party viewers.
This ASP.NET Core PDF viewer solution provides comprehensive features including form filling, text selection, digital signatures, and the ability to edit PDF files. The component also supports converting Word documents (DOCX files), Excel spreadsheets, and images to PDF. Whether you're building a simple document viewer or a complex document management system, IronPDF provides the tools and support you need.
The library's tag helper integration and extensive documentation make implementation straightforward. Your project's home page can display PDF files directly, while backend processing handles complex PDF generation tasks. The viewer maintains consistent behavior whether loaded from the wwwroot folder, generated dynamically, or retrieved from external sources. With built-in theme support and customizable width settings, you can match your application's design perfectly.
Ready to implement PDF viewing in your .NET Core Web Application?
For production use, licenses start at $749 and include comprehensive support and updates. Visit the documentation for detailed API references and advanced features. Refer to our extensive code examples to quickly implement PDF functionality in your ASP.NET Core projects.








