A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

Printing PDF Files in ASP.NET (Developer Guide)Skip to footer content
USING IRONPDF

How to Print PDF Files Programmatically in ASP.NET

ASP .NET print PDF file tasks often involve unique challenges that developers frequently encounter. Whether you're generating PDF documents for invoices, reports, or shipping labels, implementing reliable print functionality requires navigating server-client architecture complexities.

In this article, we'll show you how to handle PDF printing tasks using IronPDF's powerful PDF library for .NET.

Understanding the Challenge

Traditional desktop applications can directly access the default printer, but ASP.NET Core applications face several hurdles when printing PDF documents:

// This fails in ASP.NET - wrong approach
Process.Start(@"C:\Files\document.pdf"); // Works locally, crashes on server
// This fails in ASP.NET - wrong approach
Process.Start(@"C:\Files\document.pdf"); // Works locally, crashes on server
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The code above illustrates a common mistake. The server environment lacks direct printer access, and the system throws errors due to IIS permission restrictions. Another thing to remember is that web applications must handle both server-side and client-side printing scenarios effectively.

Getting Started with IronPDF

IronPDF provides a complete .NET core solution for generating PDF documents and printing them without external dependencies like Adobe Reader. Let's install package IronPDF using NuGet:

Install-Package IronPdf

This .NET library works seamlessly across operating systems, eliminating compatibility issues that plague other libraries. This tool works well in Microsoft Windows and other OS environments.

Creating and Printing PDF Documents Server-Side with Default Printer

Here's how to generate and print a PDF document from HTML markup in your ASP.NET controller:

using IronPdf;
using Microsoft.AspNetCore.Mvc;
using System.Drawing; 
public class PdfController : Controller
{
    public IActionResult Index()
    {
        // Initialize the renderer
        var renderer = new ChromePdfRenderer();
        // Configure print-optimized settings
        renderer.RenderingOptions.PrintHtmlBackgrounds = true;
        renderer.RenderingOptions.MarginBottom = 10;
        renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
        // Generate PDF from HTML
        var pdf = renderer.RenderHtmlAsPdf("<h1>Invoice</h1><p>Total: $749</p>");
        // Print to default printer
        pdf.Print();
        return Ok("Document sent to printer");
    }
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;
using System.Drawing; 
public class PdfController : Controller
{
    public IActionResult Index()
    {
        // Initialize the renderer
        var renderer = new ChromePdfRenderer();
        // Configure print-optimized settings
        renderer.RenderingOptions.PrintHtmlBackgrounds = true;
        renderer.RenderingOptions.MarginBottom = 10;
        renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
        // Generate PDF from HTML
        var pdf = renderer.RenderHtmlAsPdf("<h1>Invoice</h1><p>Total: $749</p>");
        // Print to default printer
        pdf.Print();
        return Ok("Document sent to printer");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The ChromePdfRenderer handles the conversion while preserving CSS styling and font size formatting. This example shows basic printing to the default printer without user interaction.

Output

Network Printer Configuration

For enterprise environments requiring specific printer routing:

public IActionResult PrintToNetworkPrinter(string filePath)
{
    // Load existing PDF file
    var pdfDocument = PdfDocument.FromFile(filePath);
    // Get print document for advanced settings
    var printDocument = pdfDocument.GetPrintDocument();
    // Specify network printer
    printDocument.PrinterSettings.PrinterName = @"\\server\printer";
    printDocument.PrinterSettings.Copies = 2;
    // Configure page settings
    printDocument.DefaultPageSettings.Landscape = false;
    var renderer = printDocument.PrinterSettings.PrinterResolution;
    // Execute print
    printDocument.Print();
    return Json(new { success = true });
}
public IActionResult PrintToNetworkPrinter(string filePath)
{
    // Load existing PDF file
    var pdfDocument = PdfDocument.FromFile(filePath);
    // Get print document for advanced settings
    var printDocument = pdfDocument.GetPrintDocument();
    // Specify network printer
    printDocument.PrinterSettings.PrinterName = @"\\server\printer";
    printDocument.PrinterSettings.Copies = 2;
    // Configure page settings
    printDocument.DefaultPageSettings.Landscape = false;
    var renderer = printDocument.PrinterSettings.PrinterResolution;
    // Execute print
    printDocument.Print();
    return Json(new { success = true });
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This approach provides complete control over printer settings, including paper format and resolution, which is vital for correct drawing and layout.

Output

How to Print PDF Files Programmatically in ASP.NET: Figure 2 - Printing PDFs with Network printing

Print Confirmation

How to Print PDF Files Programmatically in ASP.NET: Figure 3 - Success message for PDF print job

Client-Side Printing Strategy

Since browsers restrict direct printer access, implement client-side printing by serving the PDF file for download:

public IActionResult GetRawPrintablePdf()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf(GetInvoiceHtml());
        // This header tells the browser to display the file inline.
        // We use IHeaderDictionary indexer to prevent ArgumentException.
        **HttpContext context**.Response.Headers["Content-Disposition"] = "inline; filename=invoice.pdf";
        return File(pdf.BinaryData, "application/pdf");
    }
    public IActionResult PrintUsingClientWrapper()
    {
        var printUrl = Url.Action(nameof(GetRawPrintablePdf));
        // Use a simple HTML/JavaScript wrapper to force the print dialog
        var html = new StringBuilder();
        html.AppendLine("<!DOCTYPE html>");
        html.AppendLine("<html lang=\"en\">");
        html.AppendLine("<head>");
        html.AppendLine("    <title>Print Document</title>");
        html.AppendLine("</head>");
        html.AppendLine("<body>");
        // Load the PDF from the 'GetRawPrintablePdf' action into an invisible iframe.
        html.AppendLine($"    <iframe src='{printUrl}' style='position:absolute; top:0; left:0; width:100%; height:100%; border:none;'></iframe>");
        html.AppendLine("    <script>");
        // Wait for the iframe (and thus the PDF) to load, then trigger the print dialog.
        html.AppendLine("        window.onload = function() {");
        html.AppendLine("            // Wait briefly to ensure the iframe content is rendered before printing.");
        html.AppendLine("            setTimeout(function() {");
        html.AppendLine("                window.print();");
        html.AppendLine("            }, 100);");
        html.AppendLine("        };");
        html.AppendLine("    </script>");
        html.AppendLine("</body>");
        html.AppendLine("</html>");
        return Content(html.ToString(), "text/html");
    }
    private string GetInvoiceHtml()
    {
        // Build HTML with proper structure
        return @"
        <html>
        <head>
            <style>
                body { font-family: Arial, sans-serif; }
                .header { font-weight: bold; color: #1e40af; border-bottom: 2px solid #3b82f6; padding-bottom: 5px; }
                .content { padding-top: 10px; }
            </style>
        </head>
        <body>
            <div class='header'>Invoice Summary (Client View)</div>
            <div class='content'>
                <p>Document content: This file is optimized for printing.</p>
                <p>Total Amount: <b>$749.00</b></p>
            </div>
        </body>
        </html>";
    }
public IActionResult GetRawPrintablePdf()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf(GetInvoiceHtml());
        // This header tells the browser to display the file inline.
        // We use IHeaderDictionary indexer to prevent ArgumentException.
        **HttpContext context**.Response.Headers["Content-Disposition"] = "inline; filename=invoice.pdf";
        return File(pdf.BinaryData, "application/pdf");
    }
    public IActionResult PrintUsingClientWrapper()
    {
        var printUrl = Url.Action(nameof(GetRawPrintablePdf));
        // Use a simple HTML/JavaScript wrapper to force the print dialog
        var html = new StringBuilder();
        html.AppendLine("<!DOCTYPE html>");
        html.AppendLine("<html lang=\"en\">");
        html.AppendLine("<head>");
        html.AppendLine("    <title>Print Document</title>");
        html.AppendLine("</head>");
        html.AppendLine("<body>");
        // Load the PDF from the 'GetRawPrintablePdf' action into an invisible iframe.
        html.AppendLine($"    <iframe src='{printUrl}' style='position:absolute; top:0; left:0; width:100%; height:100%; border:none;'></iframe>");
        html.AppendLine("    <script>");
        // Wait for the iframe (and thus the PDF) to load, then trigger the print dialog.
        html.AppendLine("        window.onload = function() {");
        html.AppendLine("            // Wait briefly to ensure the iframe content is rendered before printing.");
        html.AppendLine("            setTimeout(function() {");
        html.AppendLine("                window.print();");
        html.AppendLine("            }, 100);");
        html.AppendLine("        };");
        html.AppendLine("    </script>");
        html.AppendLine("</body>");
        html.AppendLine("</html>");
        return Content(html.ToString(), "text/html");
    }
    private string GetInvoiceHtml()
    {
        // Build HTML with proper structure
        return @"
        <html>
        <head>
            <style>
                body { font-family: Arial, sans-serif; }
                .header { font-weight: bold; color: #1e40af; border-bottom: 2px solid #3b82f6; padding-bottom: 5px; }
                .content { padding-top: 10px; }
            </style>
        </head>
        <body>
            <div class='header'>Invoice Summary (Client View)</div>
            <div class='content'>
                <p>Document content: This file is optimized for printing.</p>
                <p>Total Amount: <b>$749.00</b></p>
            </div>
        </body>
        </html>";
    }
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The PDF document opens in the browser where users can trigger printing through their default printer using standard browser print dialogs. This approach is superior to making a direct server-side request for printing.

Output

How to Print PDF Files Programmatically in ASP.NET: Figure 4 - Client-Side Printing Print Dialog

Working with Various Source Code inputs

IronPDF flexibly handles various source code inputs, which is important to note for developers looking to create dynamic printing code:

public async Task<IActionResult> PrintFromMultipleSources()
{
    var renderer = new ChromePdfRenderer();
    // From URL
    var pdfFromUrl = await renderer.RenderUrlAsPdfAsync("https://example.com");
    // From HTML file path
    var pdfFromFile = renderer.RenderHtmlFileAsPdf(@"Templates\report.html");
    var pdfToStream = renderer.RenderHtmlAsPdf("<h2>PDF from Memory Stream</h2><p>This content was loaded into memory first.</p>");
// Now, write the valid PDF bytes to the stream
using (var stream = new MemoryStream(pdfToStream.BinaryData))
{
    var pdfFromStream = new PdfDocument(stream);
    // Example: Print the PDF loaded from the stream
    // pdfFromStream.Print(); 
}
pdfFromUrl.Print();
// Logging the various files handled
    var fileList = new List<string> { "URL", "File Path", "Memory Stream" };
return Ok("PDF documents processed and 'example.com' printed to default server printer.");
}
public async Task<IActionResult> PrintFromMultipleSources()
{
    var renderer = new ChromePdfRenderer();
    // From URL
    var pdfFromUrl = await renderer.RenderUrlAsPdfAsync("https://example.com");
    // From HTML file path
    var pdfFromFile = renderer.RenderHtmlFileAsPdf(@"Templates\report.html");
    var pdfToStream = renderer.RenderHtmlAsPdf("<h2>PDF from Memory Stream</h2><p>This content was loaded into memory first.</p>");
// Now, write the valid PDF bytes to the stream
using (var stream = new MemoryStream(pdfToStream.BinaryData))
{
    var pdfFromStream = new PdfDocument(stream);
    // Example: Print the PDF loaded from the stream
    // pdfFromStream.Print(); 
}
pdfFromUrl.Print();
// Logging the various files handled
    var fileList = new List<string> { "URL", "File Path", "Memory Stream" };
return Ok("PDF documents processed and 'example.com' printed to default server printer.");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The lines above demonstrate how to create a new list of file sources handled. Each method preserves the document structure and graphics while maintaining print quality.

How to Print PDF Files Programmatically in ASP.NET: Figure 5

Error Handling and Logging

Implement robust error handling for production environments:

using System.Drawing.Printing; // For PrinterSettings
// ... other usings ...
public IActionResult SafePrint(string documentId)
{
    try
    {
        var pdf = LoadPdfDocument(documentId);
        // Verify printer availability
        if (!PrinterSettings.InstalledPrinters.Cast<string>()
            .Contains("Target Printer"))
        {
            // Log error and handle gracefully
            return BadRequest("Printer not available");
        }
        pdf.Print();
        // Log successful output
        return Ok($"Document {documentId} printed successfully");
    }
    catch (Exception ex)
    {
        // Log error details
        return StatusCode(500, "Printing failed");
    }
}
using System.Drawing.Printing; // For PrinterSettings
// ... other usings ...
public IActionResult SafePrint(string documentId)
{
    try
    {
        var pdf = LoadPdfDocument(documentId);
        // Verify printer availability
        if (!PrinterSettings.InstalledPrinters.Cast<string>()
            .Contains("Target Printer"))
        {
            // Log error and handle gracefully
            return BadRequest("Printer not available");
        }
        pdf.Print();
        // Log successful output
        return Ok($"Document {documentId} printed successfully");
    }
    catch (Exception ex)
    {
        // Log error details
        return StatusCode(500, "Printing failed");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This ensures reliable printing even when system resources are unavailable and is a key part of your print service.

Output Scenarios

Printer Not Available

If the printer specified in the code isn't available, the code will provide this error message:

How to Print PDF Files Programmatically in ASP.NET: Figure 6 - Printer not available error

PDF Successfully Printed

If your PDF is printed successfully, you should see a confirmation message such as:

How to Print PDF Files Programmatically in ASP.NET: Figure 7 - PDF Printed success message

Advanced Configuration

IronPDF's folder structure supports complex scenarios. The version of the IronPDF library you use may affect these settings:

public IActionResult ConfigureAdvancedPrinting(object sender, EventArgs e)
{
    var renderer = new ChromePdfRenderer();
    // Configure rendering options
    renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
    renderer.RenderingOptions.EnableJavaScript = true;
    renderer.RenderingOptions.RenderDelay = 500; // Wait for dynamic content
    // Generate complex PDF documents
    var pdf = renderer.RenderHtmlAsPdf(GetDynamicContent());
    // Apply security settings
    pdf.SecuritySettings.AllowUserPrinting = true;
    pdf.MetaData.Author = "Your Company";
    return File(pdf.BinaryData, "application/pdf");
}
public IActionResult ConfigureAdvancedPrinting(object sender, EventArgs e)
{
    var renderer = new ChromePdfRenderer();
    // Configure rendering options
    renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
    renderer.RenderingOptions.EnableJavaScript = true;
    renderer.RenderingOptions.RenderDelay = 500; // Wait for dynamic content
    // Generate complex PDF documents
    var pdf = renderer.RenderHtmlAsPdf(GetDynamicContent());
    // Apply security settings
    pdf.SecuritySettings.AllowUserPrinting = true;
    pdf.MetaData.Author = "Your Company";
    return File(pdf.BinaryData, "application/pdf");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The command to print is simply pdf.Print() once the document is generated.

IronPrint Alternative

For specialized printing requirements, Iron Software also offers IronPrint, a dedicated .NET printing library with enhanced cross-platform support. You can find a link to more information on their website. The primary parameter is simply the file path. The product description is available on their website.

Conclusion

IronPDF transforms ASP.NET PDF printing from a complex challenge into straightforward implementation. Without requiring Adobe Reader or external dependencies, you can generate and print PDF files with minimal code. The PDF library handles everything from HTML conversion to printer configuration, making it ideal for both server-side automation and client-side printing scenarios.

Ready to streamline your PDF printing workflow? Get started for free today with the free trial and experience how IronPDF simplifies document processing in your ASP.NET applications. With comprehensive documentation and direct engineering support, you'll have production-ready PDF printing running in minutes.

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 ...Read More
Ready to Get Started?
Nuget Downloads 15,824,053 | Version: 2025.10 just released