C#에서 프린터 이름을 가져오는 방법

This article was translated from English: Does it need improvement?
Translated
View the article in English

시스템에 어떤 프린터가 설치되어 있는지 아는 것은 문서를 인쇄하는 .NET 애플리케이션에 공통된 전제 조건입니다. 사용자가 드롭다운에서 프린터를 선택할 수 있도록 하거나 특정 장치로 자동으로 인쇄 작업을 라우팅하는 것이 목표이든, 프로그램적으로 프린터 이름을 검색하는 것이 첫 번째 단계입니다.

IronPrint는 현재 Windows 기계에 설치된 모든 프린터를 List<string>로 반환하는 단일 정적 메서드 — Printer.GetPrinterNames() —을 제공합니다. 아래에서 설치, 동기 및 비동기 검색, 선택한 프린터 이름을 인쇄 작업에 입력하는 방법을 다룹니다.

Quickstart: 프린터 이름 검색

  1. NuGet을 통해 IronPrint 설치: Install-Package IronPrint
  2. 파일에 using IronPrint; 추가
  3. Printer.GetPrinterNames()을 호출하여 프린터 이름의 List<string>을 가져옵니다
  4. 목록을 반복하여 각 이름을 표시하거나 저장
  5. 인쇄 시 선택한 이름을 PrintSettings.PrinterName으로 전달합니다
  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronPrint 설치하기

    PM > Install-Package IronPrint
  2. 다음 코드 조각을 복사하여 실행하세요.

    using IronPrint;
    
    // Retrieve every printer installed on this machine
    List<string> printers = Printer.GetPrinterNames();
    
    foreach (var name in printers)
    {
        Console.WriteLine(name);
    }
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

    무료 체험판으로 오늘 프로젝트에서 IronPrint 사용 시작하기

    arrow pointer

설치된 모든 프린터 이름을 나열하는 방법은?

Printer.GetPrinterNames()은 운영 체제를 쿼리하여 List<string>로 등록된 모든 프린터를 반환합니다. 이 방법을 한 번 호출하고 결과를 반복합니다:

:path=/static-assets/print/content-code-examples/how-to/retrieve-printer-names/retrieve-printer-names-list-all-printers.cs
using IronPrint;
using System;
using System.Collections.Generic;

// List every installed printer
List<string> printerNames = Printer.GetPrinterNames();

Console.WriteLine($"Found {printerNames.Count} printer(s):\n");

// Print each printer name
foreach (string name in printerNames)
{
    Console.WriteLine($"  • {name}");
}
Imports IronPrint
Imports System
Imports System.Collections.Generic

' List every installed printer
Dim printerNames As List(Of String) = Printer.GetPrinterNames()

Console.WriteLine($"Found {printerNames.Count} printer(s):" & vbCrLf)

' Print each printer name
For Each name As String In printerNames
    Console.WriteLine($"  • {name}")
Next
$vbLabelText   $csharpLabel

콘솔 출력

3개의 프린터가 발견되었습니다:

• Microsoft Print to PDF
• HP LaserJet Pro MFP M428
  • OneNote (데스크톱)

반환된 목록에는 로컬 프린터, 네트워크 프린터 및 가상 인쇄 드라이버가 포함되어 있습니다. 각 문자열은 Windows 설정 > 프린터 및 스캐너 패널에 표시된 정확한 이름과 일치하므로 인쇄 설정 구성에서 직접 사용할 수 있습니다.

프린터가 설치되지 않은 경우 메서드는 예외를 던지지 않고 빈 목록을 반환합니다. 사용자에게 옵션을 제시하기 전에 빠른 printerNames.Count 확인만 필요합니다.

프린터 이름을 비동기적으로 검색하는 방법은?

UI 스레드를 차단할 수 없는 애플리케이션의 경우 — WPF, MAUI, 또는 ASP.NET 웹 앱 — IronPrint는 Printer.GetPrinterNamesAsync()을 제공합니다. 이 메서드는 Task<List<string>>을 반환하며 동기적 동반자와 동일하게 작동합니다:

:path=/static-assets/print/content-code-examples/how-to/retrieve-printer-names/retrieve-printer-names-async-printer-names.cs
using IronPrint;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

// Retrieve printer names asynchronously
List<string> printerNames = await Printer.GetPrinterNamesAsync();

// Print each printer name
foreach (string name in printerNames)
{
    Console.WriteLine(name);
}
Imports IronPrint
Imports System
Imports System.Collections.Generic
Imports System.Threading.Tasks

' Retrieve printer names asynchronously
Dim printerNames As List(Of String) = Await Printer.GetPrinterNamesAsync()

' Print each printer name
For Each name As String In printerNames
    Console.WriteLine(name)
Next
$vbLabelText   $csharpLabel

다른 비동기 API와 마찬가지로 호출을 await합니다. 결과는 List<string>이며, GetPrinterNames()에 의해 반환되어 추가 구문 분석이나 변환이 필요하지 않습니다. 이 비동기 패턴은 async Task 컨트롤러 액션 및 async void 이벤트 핸들러와 자연스럽게 통합됩니다.

특정 프린터 이름으로 인쇄하는 방법은?

프린터 이름을 얻으면, 이를 PrintSettings.PrinterName에 할당하고 설정 객체를 Printer.Print()에 전달합니다. 이렇게 하면 대화 상자를 표시하지 않고 선택한 프린터로 문서를 직접 전송합니다:

:path=/static-assets/print/content-code-examples/how-to/retrieve-printer-names/retrieve-printer-names-print-to-specific-printer.cs
using IronPrint;
using System.Collections.Generic;

// Retrieve available printers
List<string> printers = Printer.GetPrinterNames();

// Select a printer matching "LaserJet", or fall back to the first available
string targetPrinter = printers.Find(p => p.Contains("LaserJet"))
                       ?? printers[0];

// Configure print settings
PrintSettings settings = new PrintSettings
{
    PrinterName = targetPrinter,
    PaperSize = PaperSize.A4,
    NumberOfCopies = 1
};

// Print the document
Printer.Print("invoice.pdf", settings);
Imports IronPrint
Imports System.Collections.Generic

' Retrieve available printers
Dim printers As List(Of String) = Printer.GetPrinterNames()

' Select a printer matching "LaserJet", or fall back to the first available
Dim targetPrinter As String = printers.Find(Function(p) p.Contains("LaserJet")) _
                       OrElse printers(0)

' Configure print settings
Dim settings As New PrintSettings With {
    .PrinterName = targetPrinter,
    .PaperSize = PaperSize.A4,
    .NumberOfCopies = 1
}

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

PrintSettingsDpi, PaperOrientation, Grayscale, PaperMargins 등의 추가 속성을 지원합니다. 전체 목록은 PrintSettings API 참조인쇄 설정 안내서에서 참조하세요.

Printer.GetPrinterTrays(printerName)을 사용하여 특정 용지함에서 용지를 끌어와야 하는 경우 유용한 주어진 프린터에 대해 이용 가능한 용지함을 검색합니다.

내 다음 단계는 무엇인가요?

다음 네 가지 작업을 다뤘습니다: IronPrint 설치, GetPrinterNames()을 사용한 모든 프린터 이름 나열, GetPrinterNamesAsync()으로 비동기적으로 동일한 쿼리 실행, PrintSettings.PrinterName을 통해 특정 프린터에 문서 라우팅.

추가 읽기와 심도 있는 예제를 위해, 다음 리소스를 탐색하세요:

무료 체험판 라이선스 받기를 통해 모든 기능을 실제 환경에서 시험하거나, 배포를 준비 중이라면 라이선스 옵션 보기.

자주 묻는 질문

T126: C#에서 프린터 이름을 검색하는 가장 쉬운 방법은 IronPrint .NET을 사용하여 단일 메서드 호출로 설치된 프린터 목록을 얻는 것입니다.

T127: IronPrint를 사용하여 프린터 이름을 비동기로 검색할 수 있습니까?

T128: 예, IronPrint .NET은 비동기 작업을 지원하여 메인 스레드를 차단하지 않고 프린터 이름을 검색할 수 있습니다.

T129: IronPrint를 사용하여 이름으로 특정 프린터로 인쇄할 수 있습니까?

T130: 당연히 됩니다. IronPrint .NET을 사용하여 프린터 이름을 지정하면, 선택한 설치된 프린터로 문서를 직접 인쇄할 수 있습니다.

T131: IronPrint는 모든 .NET 플랫폼에서 프린터 이름 검색을 지원합니까?

T132: IronPrint .NET은 다양한 .NET 플랫폼과 함께 작동하도록 설계되어 있어, 다양한 환경에서 프린터 이름을 원활하게 검색할 수 있습니다.

T133: IronPrint는 네트워크 환경에서 프린터 이름을 어떻게 처리합니까?

T134: IronPrint .NET은 로컬 및 네트워크 프린터의 이름을 검색할 수 있어, 다양한 네트워크 구성에서 사용할 수 있습니다.

T135: 이 페이지는 IronPrint .NET을 사용하여 C#에서 설치된 프린터 이름을 검색하는 방법에 대한 상세한 가이드를 제공하며, 동기 및 비동기 메서드와 이름으로 프린터 지정 기능을 포함합니다.

Curtis Chau
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

시작할 준비 되셨나요?
Nuget 다운로드 44,051 | 버전: 2026.7 방금 출시
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronPrint
샘플을 실행하세요 문서가 프린터로 전송되는 것을 지켜보세요.