Skip to footer content
USING IRONPDF

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

IronPDF enables seamless PDF viewing in ASP.NET Core applications by generating PDFs server-side and leveraging browsers' built-in PDF viewers, eliminating the need for plugins while supporting cross-platform deployment in Docker containers and cloud environments.

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 files or install Adobe Acrobat Reader. This tutorial demonstrates how IronPDF simplifies PDF display, saving, and printing in your ASP.NET Core 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 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 PDFs server-side using its ChromePdfRenderer class. The renderer uses a complete Chrome engine under the hood, ensuring your 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 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 PdfViewerApp
dotnet new mvc -n PdfViewerApp
cd PdfViewerApp
SHELL

How Do You Install IronPDF in Your .NET Project?

Install IronPDF via NuGet Package Manager in your 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 receives frequent updates to ensure compatibility with the latest frameworks. For detailed installation instructions, visit the IronPDF installation guide. The package includes all necessary components for PDF generation, editing, and processing. For Docker deployments, IronPDF provides optimized container images that minimize deployment complexity—a critical consideration for DevOps engineers managing containerized environments.

How Can You Display PDF Files in the Browser Using ASP.NET Core?

Creating and displaying PDFs in the browser requires just a few lines of code. Here's a complete controller action that generates a PDF from HTML and displays it inline:

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");
    }
}
$vbLabelText   $csharpLabel

The 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. 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—essential for maintaining reliability in Azure deployments and AWS Lambda environments.

Output

PDF viewer interface showing a simple invoice document with invoice number 12345 dated 2025-10-30. The ASP.NET Core PDF viewer successfully displays a rendered invoice document with page navigation controls and zoom options in the toolbar.

For existing HTML files or Razor pages, you can use alternative rendering methods:

// Render from URL - useful for complex pages
var pdf = renderer.RenderUrlAsPdf("___PROTECTED_URL_58___");
// 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");
// For containerized applications, use environment-specific paths
var basePath = Environment.GetEnvironmentVariable("APP_BASE_PATH") ?? "wwwroot";
var pdf = renderer.RenderHtmlFileAsPdf($"{basePath}/templates/report.html");
// Render from URL - useful for complex pages
var pdf = renderer.RenderUrlAsPdf("___PROTECTED_URL_58___");
// 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");
// For containerized applications, use environment-specific paths
var basePath = Environment.GetEnvironmentVariable("APP_BASE_PATH") ?? "wwwroot";
var pdf = renderer.RenderHtmlFileAsPdf($"{basePath}/templates/report.html");
$vbLabelText   $csharpLabel

These methods provide flexibility in how you source your HTML content while maintaining high-quality PDF output. You can also load existing PDF documents, edit PDFs, and 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, check the API reference.

For DevOps engineers managing microservices architectures, IronPDF's native vs remote engine architecture provides deployment flexibility. The remote engine option allows you to separate PDF rendering into a dedicated service, improving resource utilization and enabling horizontal scaling.

How Do Users Save PDF Documents from the Browser?

To enable users to download PDFs instead of viewing them inline, modify the Content-Disposition header. This feature is essential for applications where users need 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");
}

// Health check endpoint for container orchestration
[HttpGet("/health/pdf-generator")]
public IActionResult HealthCheck()
{
    try
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<p>Health Check</p>");
        return Ok(new { status = "healthy", timestamp = DateTime.UtcNow });
    }
    catch (Exception ex)
    {
        return StatusCode(503, new { status = "unhealthy", error = ex.Message });
    }
}
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");
}

// Health check endpoint for container orchestration
[HttpGet("/health/pdf-generator")]
public IActionResult HealthCheck()
{
    try
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<p>Health Check</p>");
        return Ok(new { status = "healthy", timestamp = DateTime.UtcNow });
    }
    catch (Exception ex)
    {
        return StatusCode(503, new { status = "unhealthy", error = ex.Message });
    }
}
$vbLabelText   $csharpLabel

Adding the filename parameter automatically sets the Content-Disposition header to "attachment," prompting the browser to download the file. Users can also save PDFs displayed inline using their browser's save functionality (Ctrl+S or the PDF viewer toolbar). The health check endpoint shown above is crucial for Kubernetes deployments and container orchestration platforms, ensuring your PDF service remains responsive.

Output

PDF viewer showing a document with 'Download Me' text and IronPDF for .NET logo, displayed in a browser at 100% zoom. The PDF viewer successfully displays the generated invoice document with download functionality enabled through IronPDF for .NET.

Why Should You Use Streams for Large PDF Files?

For better memory efficiency with large 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");
}

// Async streaming for better resource utilization
public async Task<IActionResult> StreamPdfAsync()
{
    var renderer = new ChromePdfRenderer();
    // Configure for optimal container performance
    renderer.RenderingOptions.Timeout = 60000; // 60 seconds for complex documents
    renderer.RenderingOptions.RenderDelay = 500; // Allow JS to execute

    var html = await LoadHtmlTemplateAsync();
    var pdf = await Task.Run(() => renderer.RenderHtmlAsPdf(html));

    var stream = pdf.Stream;
    stream.Position = 0;
    return File(stream, "application/pdf", "async-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");
}

// Async streaming for better resource utilization
public async Task<IActionResult> StreamPdfAsync()
{
    var renderer = new ChromePdfRenderer();
    // Configure for optimal container performance
    renderer.RenderingOptions.Timeout = 60000; // 60 seconds for complex documents
    renderer.RenderingOptions.RenderDelay = 500; // Allow JS to execute

    var html = await LoadHtmlTemplateAsync();
    var pdf = await Task.Run(() => renderer.RenderHtmlAsPdf(html));

    var stream = pdf.Stream;
    stream.Position = 0;
    return File(stream, "application/pdf", "async-document.pdf");
}
$vbLabelText   $csharpLabel

This approach reduces memory consumption by streaming PDFs directly to the response without creating intermediate byte arrays. You can also load existing PDFs from the wwwroot folder, edit them, and stream modified versions. For 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.

For container deployments, the async PDF generation approach prevents blocking threads and improves application throughput—critical for maintaining responsive services in orchestrated environments.

Can Users Print PDF Documents Directly from ASP.NET Core Web Applications?

IronPDF optimizes PDFs for printing by configuring the appropriate CSS media type and page settings. This 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");
}

// Container-optimized configuration
public IActionResult ConfigureForContainer()
{
    var renderer = new ChromePdfRenderer();
    // Disable GPU for container compatibility
    renderer.RenderingOptions.EnableJavaScript = true;
    renderer.RenderingOptions.RenderDelay = 0; // No artificial delays
    renderer.RenderingOptions.Timeout = 30000; // 30 second timeout

    // Use environment variables for configuration
    var printDpi = int.Parse(Environment.GetEnvironmentVariable("PDF_PRINT_DPI") ?? "300");
    renderer.RenderingOptions.PrintHtmlBackgrounds = true;

    return Ok("Configured for container environment");
}
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");
}

// Container-optimized configuration
public IActionResult ConfigureForContainer()
{
    var renderer = new ChromePdfRenderer();
    // Disable GPU for container compatibility
    renderer.RenderingOptions.EnableJavaScript = true;
    renderer.RenderingOptions.RenderDelay = 0; // No artificial delays
    renderer.RenderingOptions.Timeout = 30000; // 30 second timeout

    // Use environment variables for configuration
    var printDpi = int.Parse(Environment.GetEnvironmentVariable("PDF_PRINT_DPI") ?? "300");
    renderer.RenderingOptions.PrintHtmlBackgrounds = true;

    return Ok("Configured for container environment");
}
$vbLabelText   $csharpLabel

Setting CssMediaType to Print applies print-specific CSS styles, ensuring the document looks correct when printed. The margin settings provide proper spacing for physical paper. Users can print PDFs 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.

PDF viewer interface showing a print-optimized document with the message 'This document is optimized for printing' displayed in the center of a white page. The PDF viewer displays a confirmation message when a document has been optimized for printing, ensuring users know their file is ready for high-quality output.

How Does IronPDF Support Cross-Platform and Container Deployments?

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 your code works everywhere without modification.

Cross-platform support diagram showing .NET compatibility across multiple versions, operating systems, cloud platforms, and development environments. IronPDF's comprehensive cross-platform support includes compatibility with .NET 9 through Framework 4.6.2+, runs on Windows, Linux, and Mac, and integrates with major cloud providers and development tools.

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, handling files in the wwwroot folder or other locations correctly. For containerized deployments, check the Docker deployment guide. The package includes all necessary dependencies for each platform, requiring no additional configuration beyond standard ASP.NET Core requirements.

For production container deployments, consider this Dockerfile example:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80

# Install IronPDF dependencies for Linux
RUN apt-get update && apt-get install -y \
    libgdiplus \
    libc6-dev \
    libx11-6 \
    && rm -rf /var/lib/apt/lists/*

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["PdfViewerApp.csproj", "./"]
RUN dotnet restore "PdfViewerApp.csproj"
COPY . .
RUN dotnet build "PdfViewerApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "PdfViewerApp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PdfViewerApp.dll"]

Get started with a free trial and transform your document viewer capabilities today.

What Are the Key Benefits of Using IronPDF for ASP.NET Core PDF Viewing?

IronPDF transforms PDF handling in ASP.NET Core applications by combining server-side generation with browser-native viewing. With just a few lines of code, you can create professional PDFs from HTML, display them 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 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 PDFs. 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 you need.

The library's tag helper integration and extensive documentation make implementation straightforward. Your project can display PDFs directly while backend processing handles complex PDF generation tasks. The viewer maintains consistent behavior whether loading from the wwwroot folder, generating dynamically, or retrieving from external sources. With built-in theme support and customizable width settings, you can match your application's design perfectly. For DevOps teams, the IronPDF Slim package offers reduced deployment size, addressing container size constraints in orchestrated environments.

Ready to implement PDF viewing in your .NET Core Web Application?

For production use, licenses start at $799 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.

IronPDF licensing page showing four perpetual license tiers (Lite, Plus, Professional, and Unlimited) with pricing, developer limits, and a toggle between IronPDF and Iron Suite options. IronPDF offers various licensing options ranging from $749 for single developers to $3,999 for unlimited usage, with all licenses including 1-year support and updates.

Frequently Asked Questions

How can I display PDFs in an ASP.NET Core application?

You can display PDFs in an ASP.NET Core application using IronPDF, which provides functionalities to render PDF files directly within your application.

What are the steps to save a PDF in ASP.NET Core using IronPDF?

To save a PDF in ASP.NET Core, you can use IronPDF's built-in methods to convert your document to a PDF format and then write it to a file system or a stream.

Is it possible to print PDFs in ASP.NET Core applications?

Yes, IronPDF allows you to print PDFs directly from your ASP.NET Core application by using its rendering and printing functionalities.

What are the advantages of using IronPDF in ASP.NET Core?

IronPDF offers a seamless integration with ASP.NET Core, enabling easy PDF manipulation such as viewing, saving, and printing, with minimal setup.

Can IronPDF handle large PDF documents in ASP.NET Core?

Yes, IronPDF is optimized to handle large PDF documents efficiently, ensuring smooth performance even with complex files.

Does IronPDF support PDF annotations and comments in ASP.NET Core?

IronPDF supports adding and reading annotations and comments in PDFs, enhancing the interactivity and usability of PDF documents in your ASP.NET Core application.

How do I integrate IronPDF into an existing ASP.NET Core project?

You can integrate IronPDF into your ASP.NET Core project by installing the IronPDF NuGet package and using its API to manage PDFs.

Are there any specific system requirements for using IronPDF with ASP.NET Core?

IronPDF requires .NET Core or .NET 5+ and supports all major operating systems, making it a flexible choice for ASP.NET Core projects.

Can IronPDF convert other file formats to PDF in ASP.NET Core?

Yes, IronPDF can convert various file formats such as HTML, images, and documents to PDF within an ASP.NET Core environment.

What kind of support does IronPDF offer for ASP.NET Core developers?

IronPDF provides comprehensive documentation, code samples, and responsive support to assist ASP.NET Core developers in implementing PDF functionalities.

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