How to Specify the Printer Name in C#

IronPrint's PrintSettings class exposes a PrinterName property that directs print jobs to a specific printer. We assign the exact name of the target printer as a string, pass the configured PrintSettings object to any of IronPrint's print methods, and the document goes to that printer instead of the system default.

This guide walks through setting a printer name, discovering available printers at runtime, and combining printer selection with other print settings.

Quickstart: Specify the Printer Name

  1. Install IronPrint via NuGet: Install-Package IronPrint
  2. Add using IronPrint; to the file
  3. Create a PrintSettings object
  4. Set PrinterName to the exact name of the target printer
  5. Pass settings to Printer.Print() or Printer.PrintAsync()
  1. Install IronPrint with NuGet Package Manager

    PM > Install-Package IronPrint
  2. Copy and run this code snippet.

    using IronPrint;
    
    // Print a document to a specific printer
    Printer.Print("report.pdf", new PrintSettings
    {
        PrinterName = "HP LaserJet Pro M404"
    });
  3. Deploy to test on your live environment

    Start using IronPrint in your project today with a free trial

    arrow pointer

How Do I Specify a Printer Name in C#?

We specify the target printer by assigning its name to the PrinterName property on a PrintSettings object. We then pass that object to Printer.Print.

:path=/static-assets/print/content-code-examples/how-to/specify-printer-name/set-printer-name.cs
using IronPrint;

// Configure print settings with a target printer
PrintSettings settings = new PrintSettings();
settings.PrinterName = "Microsoft Print to PDF";

// Send the document to the specified printer
Printer.Print("invoice.pdf", settings);
Imports IronPrint

' Configure print settings with a target printer
Dim settings As New PrintSettings()
settings.PrinterName = "Microsoft Print to PDF"

' Send the document to the specified printer
Printer.Print("invoice.pdf", settings)
$vbLabelText   $csharpLabel

We first instantiate PrintSettings, which initializes with PrinterName = null — meaning the OS default printer. We then override PrinterName with the exact string name of the target printer. When we call Printer.Print, IronPrint sends the job directly to that printer's queue.

Two critical details to keep in mind. First, the printer name must match exactly what the operating system reports — this comparison is case-sensitive. A mismatch like "hp laserjet" instead of "HP LaserJet" will fail silently or throw an error. Second, if the user opens a print dialog via ShowPrintDialog, the dialog selection overrides whatever PrinterName was set in code. This is by design — the dialog gives users final control.

How Do I Discover Available Printers?

Rather than hardcoding printer names, we can query the system at runtime using Printer.GetPrinterNames(). This method returns a List<string> containing every installed printer on the machine.

:path=/static-assets/print/content-code-examples/how-to/specify-printer-name/discover-printers.cs
using IronPrint;

// Discover all installed printers
List<string> printers = Printer.GetPrinterNames();

foreach (string name in printers)
{
    Console.WriteLine(name);
}

// Use the first available printer
if (printers.Count > 0)
{
    Printer.Print("report.pdf", new PrintSettings
    {
        PrinterName = printers[0]
    });
}
Imports IronPrint

' Discover all installed printers
Dim printers As List(Of String) = Printer.GetPrinterNames()

For Each name As String In printers
    Console.WriteLine(name)
Next

' Use the first available printer
If printers.Count > 0 Then
    Printer.Print("report.pdf", New PrintSettings With {
        .PrinterName = printers(0)
    })
End If
$vbLabelText   $csharpLabel

We call GetPrinterNames() to retrieve every printer the operating system knows about — including local, network, and virtual printers like "Microsoft Print to PDF." We then iterate through the list and select a printer by index, name matching, or any custom logic the application requires.

This discover-then-print pattern is essential for applications deployed across different machines. Hardcoding a printer name works for single-machine scenarios, but production applications should query available printers and either let the user choose or select one programmatically based on naming conventions. For a dedicated code example, see the get printer names example.

How Do I Combine Printer Name with Other Settings?

The PrintSettings class exposes PrinterName alongside properties for paper size, orientation, DPI, margins, copy count, and flattening. We configure everything in a single object.

:path=/static-assets/print/content-code-examples/how-to/specify-printer-name/combined-settings.cs
using IronPrint;

// Build a fully configured print job targeting a specific printer
PrintSettings settings = new PrintSettings
{
    PrinterName = "Office Color Printer",
    PaperSize = PaperSize.A4,
    PaperOrientation = PaperOrientation.Portrait,
    Dpi = 300,
    NumberOfCopies = 2,
    PaperMargins = new Margins(15, 15, 15, 15),
    Grayscale = false
};

// Print a branded report to the color printer
Printer.Print("quarterly-report.pdf", settings);
Imports IronPrint

' Build a fully configured print job targeting a specific printer
Dim settings As New PrintSettings With {
    .PrinterName = "Office Color Printer",
    .PaperSize = PaperSize.A4,
    .PaperOrientation = PaperOrientation.Portrait,
    .Dpi = 300,
    .NumberOfCopies = 2,
    .PaperMargins = New Margins(15, 15, 15, 15),
    .Grayscale = False
}

' Print a branded report to the color printer
Printer.Print("quarterly-report.pdf", settings)
$vbLabelText   $csharpLabel

We use object initializer syntax for readability. PrinterName routes the job to "Office Color Printer" while the remaining properties control the output format. Dpi at 300 produces sharp text and graphics. PaperMargins accepts four millimeter values through the Margins constructor — top, right, bottom, left.

IronPrint validates the configuration as a unit and submits the combined settings to the printer driver in a single job. For additional options like tray selection and grayscale mode, see the full print settings guide.

How Do I Select a Printer and Print Asynchronously?

For applications where blocking the main thread is not an option — such as WPF or WinForms apps — we use Printer.GetPrinterNamesAsync() and Printer.PrintAsync(). Both return a Task, keeping the UI responsive.

:path=/static-assets/print/content-code-examples/how-to/specify-printer-name/async-printer-select.cs
using IronPrint;
using System.Threading.Tasks;

public class PrintService
{
    public async Task PrintToFirstAvailableAsync(string filePath)
    {
        // Discover printers without blocking the UI
        List<string> printers = await Printer.GetPrinterNamesAsync();

        if (printers.Count == 0)
        {
            Console.WriteLine("No printers found.");
            return;
        }

        // Configure and print to the first available printer
        PrintSettings settings = new PrintSettings
        {
            PrinterName = printers[0],
            Dpi = 300
        };

        await Printer.PrintAsync(filePath, settings);
    }
}
Imports IronPrint
Imports System.Threading.Tasks

Public Class PrintService
    Public Async Function PrintToFirstAvailableAsync(filePath As String) As Task
        ' Discover printers without blocking the UI
        Dim printers As List(Of String) = Await Printer.GetPrinterNamesAsync()

        If printers.Count = 0 Then
            Console.WriteLine("No printers found.")
            Return
        End If

        ' Configure and print to the first available printer
        Dim settings As New PrintSettings With {
            .PrinterName = printers(0),
            .Dpi = 300
        }

        Await Printer.PrintAsync(filePath, settings)
    End Function
End Class
$vbLabelText   $csharpLabel

This class-based example wraps the discover-and-print logic in a reusable service. We call GetPrinterNamesAsync() to retrieve the printer list without freezing the UI, then assign the first available printer to PrinterName. The await Printer.PrintAsync call sends the job asynchronously.

In production, we might replace printers[0] with logic that matches a naming convention — such as searching for printers containing "Label" for shipping labels or "Color" for branded documents. IronPrint's async methods all accept the same PrintSettings object, so PrinterName behavior is identical between synchronous and asynchronous paths.

What Are My Next Steps?

We covered how to specify a printer name in C# using IronPrint's PrintSettings.PrinterName property, from static assignment to dynamic runtime discovery with Printer.GetPrinterNames(). The key points: printer names must match exactly (case-sensitive), null defaults to the OS default printer, and print dialogs override programmatic selection.

To continue exploring IronPrint's capabilities:

Start a free 30-day trial to test printer selection in your own projects, or view licensing options for production deployment.

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
Ready to Get Started?
Nuget Downloads 37,845 | Version: 2026.3 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronPrint
run a sample watch your document hit the printer.