푸터 콘텐츠로 바로가기
IRONPRINT 사용하여

C#에서 네트워크 프린터로 인쇄하는 방법

네트워크 프린터에서의 프로그램적 인쇄는 다양한 소프트웨어 애플리케이션에서 일반적인 작업입니다. 데스크톱, 모바일 애플리케이션 또는 웹 서비스를 구축하든 관계없이 네트워크 프린터로 문서를 직접 전송할 수 있는 기능은 소프트웨어의 사용성과 효율성을 크게 향상시킬 수 있습니다. 이번 기사에서는 C# 및 IronPrint을(를) 사용하여 네트워크 프린터로 출력하는 방법을 탐색합니다.

How to Print with Network Printer in C#

  1. IronPrint을(를) 사용하여 문서를 출력하는 새 프로젝트를 만듭니다.
  2. IronPrint을(를) 새 프로젝트에 설치합니다.
  3. 문서를 출력할 수 있는 네트워크 프린터 목록을 나열합니다.
  4. IronPrint을(를) 사용하여 PDF 문서를 출력합니다.
  5. 다이얼로그와 함께 IronPrint을(를) 사용하여 PDF 문서를 출력합니다.
  6. 프린터 설정을 사용하여 고급 인쇄를 수행합니다.

환경 설정

코딩 부분에 들어가기에 앞서, 환경이 올바르게 설정되었는지 확인해 봅시다. C#에서 네트워크 프린터로 출력하려면 다음이 필요합니다:

  1. C# 애플리케이션이 실행될 컴퓨터에서 네트워크 프린터에 액세스할 수 있어야 합니다.
  2. 프린터의 네트워크 주소(IP 주소 또는 네트워크 프린터 이름).
  3. 컴퓨터에 설치된 필요한 프린터 드라이버/드라이버.
  4. 필요할 경우 프린터 또는 드라이버를 설치할 수 있는 관리자 권한.

IronPrint

구현 세부사항으로 들어가기 전에 IronPrint를 사용하는 방법에 익숙해집시다:

  1. 설치: IronPrint는 NuGet 패키지 관리자를 통해 쉽게 설치할 수 있습니다. 간단히 NuGet 페이지를 방문하고 설치 지침을 따르세요.
  2. 문서: 빠른 시작 가이드 및 포괄적 API 참조를 위해 공식 문서를 참조하세요.

호환성 및 지원: IronPrint는 여러 환경 및 프로젝트 유형에서 광범위한 호환성과 지원을 제공합니다:

  • .NET 버전 지원: IronPrint는 C#, VB.NET, F#을 지원하며 .NET 8,7,6,5 및 Core 3.1+를 포함합니다.
  • 운영 체제 및 환경: IronPrint는 Windows(7+), macOS(10+), iOS(11+), Android API 21+(v5 "Lollipop")과 호환됩니다.
  • 프로젝트 유형: 모바일(Xamarin, MAUI, Avalonia), 데스크톱(WPF, MAUI, Windows Avalonia), 콘솔 애플리케이션을 개발하든 IronPrint는 지원합니다.

이제 다음 예제를 통해 IronPrint를 사용하여 인쇄하는 방법을 살펴보겠습니다.

using IronPrint;

namespace IronPrintDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure printer setting
            PrintSettings printSettings = new PrintSettings();
            printSettings.Dpi = 220;
            printSettings.NumberOfCopies = 10;
            printSettings.PaperOrientation = PaperOrientation.Portrait;

            // Print the document
            Printer.Print("awesomeIronPrint.pdf", printSettings);
        }
    }
}
using IronPrint;

namespace IronPrintDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure printer setting
            PrintSettings printSettings = new PrintSettings();
            printSettings.Dpi = 220;
            printSettings.NumberOfCopies = 10;
            printSettings.PaperOrientation = PaperOrientation.Portrait;

            // Print the document
            Printer.Print("awesomeIronPrint.pdf", printSettings);
        }
    }
}
$vbLabelText   $csharpLabel

System.Printing

C#에서 System.Printing 네임스페이스에는 개발자가 프린터, 인쇄 대기열, 인쇄 서버 및 인쇄 작업과 프로그래밍적으로 상호작용할 수 있는 클래스와 인터페이스가 포함되어 있습니다. 이 네임스페이스 내의 몇 가지 주요 클래스와 인터페이스는 다음과 같습니다:

  1. PrintQueue: 시스템에 연결된 프린터 또는 인쇄 장치를 나타냅니다.
  2. PrintServer: 네트워크의 인쇄 서버를 나타냅니다.
  3. PrintSystemJobInfo: 인쇄 작업의 상태 및 속성과 같은 정보를 제공합니다.
  4. PrintTicket: 용지 크기, 방향 및 인쇄 품질을 포함한 인쇄 작업 설정을 나타냅니다.

System.Printing 시작하기: 코드를 시작하기 전에 System.Printing와 함께 인쇄가 어떻게 작동하는지 기본 개념을 이해해봅시다:

  1. PrintQueue 선택: 사용하려는 프린터를 나타내는 PrintQueue 객체를 식별해야 합니다.
  2. PrintTicket 구성: 필요에 따라 용지 크기, 방향 및 복사본 수와 같은 인쇄 설정을 지정하기 위해 PrintTicket 객체를 구성할 수 있습니다.
  3. 문서 인쇄: 마지막으로, 인쇄할 문서를 선택한 PrintQueue에 보냅니다.

System.Printing로 문서 인쇄 구현: 이제 다음 예제를 통해 System.Printing로 문서를 인쇄하는 과정을 살펴봅시다:

여기 소스 코드가 있습니다:

using System;
using System.IO;
using System.Printing;

class Program
{
    static void Main(string[] args)
    {
        // Specify the path to the document to be printed on the local printer
        string documentPath = "path/to/your/document.pdf";

        // Instantiate a Printer Server object representing the local print server
        using (PrintServer printServer = new PrintServer())
        {
            // Get the default PrintQueue from the PrintServer default 
            PrintQueue defaultPrintQueue = printServer.DefaultPrintQueue;

            // Create a PrintTicket object to specify print settings (optional)
            PrintTicket printTicket = new PrintTicket();

            // Configure print settings, e.g., number of copies
            printTicket.CopyCount = 1;

            // Print the document to the default PrintQueue with the specified PrintTicket
            defaultPrintQueue.AddJob("MyPrintJob", documentPath, false, printTicket);
        }

        Console.WriteLine("Document sent to print queue.");
    }
}
using System;
using System.IO;
using System.Printing;

class Program
{
    static void Main(string[] args)
    {
        // Specify the path to the document to be printed on the local printer
        string documentPath = "path/to/your/document.pdf";

        // Instantiate a Printer Server object representing the local print server
        using (PrintServer printServer = new PrintServer())
        {
            // Get the default PrintQueue from the PrintServer default 
            PrintQueue defaultPrintQueue = printServer.DefaultPrintQueue;

            // Create a PrintTicket object to specify print settings (optional)
            PrintTicket printTicket = new PrintTicket();

            // Configure print settings, e.g., number of copies
            printTicket.CopyCount = 1;

            // Print the document to the default PrintQueue with the specified PrintTicket
            defaultPrintQueue.AddJob("MyPrintJob", documentPath, false, printTicket);
        }

        Console.WriteLine("Document sent to print queue.");
    }
}
$vbLabelText   $csharpLabel

IronPrint Vs System.Printing

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 1 - IronPrint와 System.Printing의 빠른 비교 표

이 표는 IronPrint와 System.Printing의 기능과 특성에 대한 빠른 개요를 제공하여 개발자가 특정 요구사항과 플랫폼 목표에 따라 정보를 바탕으로 한 결정을 내릴 수 있도록 돕습니다.

1단계: IronPrint를 사용하여 문서 출력용 새 프로젝트 만들기

아래와 같이 Visual Studio에서 콘솔 애플리케이션을 만드세요.

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 2 - 콘솔 애플리케이션 생성

프로젝트 이름과 위치를 제공하세요.

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 3 - 프로젝트 이름 제공

.NET 버전을 선택하세요.

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 4 - 적절한 .NET 버전 선택

이제 프로젝트가 만들어졌고 추가 코딩을 위해 준비되었습니다.

2단계: 새 프로젝트에 IronPrint 설치하기

아래와 같이 Visual Studio 패키지 관리자를 통해 IronPrint를 설치하세요.

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 5 - Visual Studio 패키지 관리자를 통해 IronPrint 검색

IronPrint는 아래 명령어를 사용하여 설치할 수도 있습니다:

Install-Package IronPrint

3단계: 문서 인쇄를 위해 사용할 수 있는 네트워크 프린터 나열

IronPrint를 사용하여 프린터 이름을 나열하려면 아래 코드를 사용하세요:

using System;
using System.Collections.Generic;
using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Get printer names using printer drivers
            List<string> printersName = Printer.GetPrinterNames();
            foreach (var printer in printersName)
            {
                Console.WriteLine(printer);
            }
        }
    }
}
using System;
using System.Collections.Generic;
using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Get printer names using printer drivers
            List<string> printersName = Printer.GetPrinterNames();
            foreach (var printer in printersName)
            {
                Console.WriteLine(printer);
            }
        }
    }
}
$vbLabelText   $csharpLabel

코드 설명

  1. 모든 사용 가능한 프린터 드라이버를 얻기 위해 Printer.GetPrinterNames을 사용하십시오.
  2. Console.WriteLine를 사용하여 이름을 출력하십시오.

산출

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 6 - 사용 가능한 프린터의 예제 출력

4단계: IronPrint를 사용하여 PDF 문서 인쇄

문서를 조용히 인쇄하려면 아래 코드를 사용하세요:

using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Print the document silently
            Printer.Print("sample.pdf");
        }
    }
}
using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Print the document silently
            Printer.Print("sample.pdf");
        }
    }
}
$vbLabelText   $csharpLabel

실행 후 출력에 표시된 것처럼 문서가 인쇄 대기열에 추가됩니다.

산출

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 7 - 인쇄 대기열에 추가되는 문서를 보여주는 예제 출력

5단계: IronPrint를 사용하여 다이얼로그로 PDF 문서 인쇄

다이얼로그를 사용하여 문서를 인쇄하려면 아래 코드를 사용하세요:

using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Print with Dialog
            Printer.ShowPrintDialog("sample.pdf");
        }
    }
}
using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Print with Dialog
            Printer.ShowPrintDialog("sample.pdf");
        }
    }
}
$vbLabelText   $csharpLabel

코드 설명

  1. IronPrint의 ShowPrintDialog를 사용하여 대화 상자로 인쇄할 수 있습니다.
  2. 다이얼로그가 열리면 문서를 인쇄할 필요한 프린터를 선택합니다.

산출

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 8 - 올바른 프린터 선택

6단계: 고급 인쇄 설정을 사용한 고급 인쇄

고급 설정을 사용하여 문서 인쇄는 IronPrint에서 지원됩니다. 다음 속성이 지원됩니다:

  1. PaperSize: 프린터에서 사용되는 용지 치수를 지정합니다.
  2. PaperOrientation: 용지의 방향, 예를 들어 자동, 세로 방향 또는 가로 방향을 정의합니다.
  3. DPI: 인치당 도트 단위로 원하는 인쇄 해상도를 설정합니다. 기본값은 주로 상업 인쇄에 사용되는 300입니다. 실제 DPI는 프린터의 기능에 의해 제한될 수 있습니다.
  4. NumberOfCopies: 문서의 동일한 복사본을 인쇄해야 하는 수를 나타냅니다.
  5. PrinterName: 인쇄 작업에 지정된 프린터의 이름을 지정합니다.
  6. PaperMargins: 밀리미터 단위로 인쇄할 여백을 결정합니다.
  7. Grayscale: 색조로 인쇄할지를 결정하는 부울 값입니다. 기본값은 false입니다.

이제 코드 예제를 보겠습니다:

using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Configure custom print settings
            PrintSettings printSettings = new PrintSettings();
            printSettings.Dpi = 150;
            printSettings.NumberOfCopies = 2;
            printSettings.PaperOrientation = PaperOrientation.Portrait;

            // Print the required document
            Printer.Print("sample.pdf", printSettings);
        }
    }
}
using IronPrint;

namespace IronPrintDemo
{
    public class Program
    {
        public static void Main()
        {
            // Configure custom print settings
            PrintSettings printSettings = new PrintSettings();
            printSettings.Dpi = 150;
            printSettings.NumberOfCopies = 2;
            printSettings.PaperOrientation = PaperOrientation.Portrait;

            // Print the required document
            Printer.Print("sample.pdf", printSettings);
        }
    }
}
$vbLabelText   $csharpLabel

코드 설명

  1. 코드는 필요한 클래스와 인쇄 메소드를 포함하는 IronPrint라는 네임스페이스를 가져오는 것으로 시작합니다.
  2. IronPrintDemo 네임스페이스 안에 'Program'이라는 공용 클래스가 선언되어 있습니다.
  3. Main 메소드는 프로그램의 진입점으로서 역할을 합니다.
  4. Main 메소드 내에서:
    • 사용자 정의 인쇄 설정을 구성하기 위해 PrintSettings라는 이름의 printSettings 객체가 인스턴스화됩니다.
    • printSettingsDpi 속성을 150으로 설정하여 인치당 150 도트의 인쇄 해상도를 나타냅니다.
    • printSettingsNumberOfCopies 속성을 2로 설정하여 문서의 동일한 복사본 두 부가 인쇄됨을 명시합니다.
    • printSettingsPaperOrientation 속성을 PaperOrientation.Portrait으로 설정하여 문서가 세로 방향으로 인쇄됨을 나타냅니다.
  5. 최종적으로, 'sample.pdf' (인쇄할 문서의 이름) 및 사용자 정의 인쇄 설정 (printSettings)을 매개변수로 하여 Printer.Print 메서드를 호출합니다. 이 메소드는 지정된 설정을 사용하여 인쇄 프로세스를 처리합니다.

산출

C#에서 네트워크 프린터로 인쇄하는 방법: 그림 9 - 인쇄 대기열에 추가된 PDF 문서 출력의 예제

라이선스

IronPrintIron Software의 Enterprise 라이브러리이며 실행하기 위해 라이선스가 필요합니다. IronPrint 라이선스 키를 추가하면 프로젝트가 제한 없이 또는 워터마크 없이 실행됩니다. 여기에서 라이선스를 구매하거나 무료 30일 체험판 키를 받으세요 여기에서.

라이선스 키를 받으면 애플리케이션의 appSettings.json 파일에 키를 넣어야 합니다.

{
  "IronPrint.License.LicenseKey": "IRONPRINT.KEY"
}

이렇게 하면 문서를 제한 없이 및 워터마크 없이 인쇄할 수 있습니다.

결론

요약하자면, IronPrint와 System.Printing는 각각의 강점을 가지고 있으며, 다양한 시나리오에 적합합니다. IronPrint는 간단함과 다재다능함에 중점을 둔 매끄럽고 크로스 플랫폼 솔루션을 제공하며, System.Printing는 네이티브 통합과 세부 설정의 제어를 제공하여 특히 Windows 기반 애플리케이션에 적합합니다. 개발자는 C# 프로젝트에 대한 이러한 인쇄 라이브러리 중에서 선택할 때 자신의 특정 요구 사항 및 플랫폼 목표를 고려해야 합니다.

IronPrint는 다양한 플랫폼과 프로젝트 유형 간의 광범위한 호환성을 제공하고 사용하기 쉬운 API를 통해 .NET 애플리케이션 내에서 문서 인쇄를 간소화합니다. 이 기사에 설명된 단계를 따르면 .NET 프로젝트에 인쇄 기능을 원활하게 통합하여 사용 가능성과 생산성을 향상시킬 수 있습니다. IronPrint와 함께 가능성을 탐색하고 응용 프로그램 내에서 효율적인 문서 인쇄의 세계를 열어보세요.

자주 묻는 질문

C#을 사용하여 네트워크 프린터로 인쇄하려면 어떻게 해야 하나요?

IronPrint 사용하면 C#에서 네트워크 프린터로 문서를 인쇄할 수 있습니다. IronPrint는 인쇄 작업을 프로그래밍 방식으로 처리하는 메서드를 제공하여 문서를 네트워크 프린터로 직접 전송할 수 있도록 합니다.

C#에서 네트워크 프린터로 인쇄를 설정하는 단계는 무엇입니까?

먼저 네트워크 프린터와 해당 주소에 접근할 수 있는지 확인하십시오. NuGet 패키지 관리자를 통해 필요한 드라이버와 IronPrint 설치합니다. 그런 다음 IronPrint의 기능을 사용하여 인쇄 작업을 관리하고 전송하십시오.

C# 프로젝트에 IronPrint 어떻게 설치하나요?

Visual Studio의 NuGet 패키지 관리자를 사용하거나 패키지 관리자 콘솔에서 Install-Package IronPrint 명령을 실행하여 IronPrint 설치할 수 있습니다.

IronPrint 와 호환되는 .NET 버전은 무엇입니까?

IronPrint C#, VB .NET 및 F#을 지원하며 .NET 8, 7, 6, 5 및 Core 3.1 이상과 호환됩니다.

IronPrint 다양한 운영 체제에서 사용할 수 있습니까?

네, IronPrint 는 Windows(7 이상), macOS(10 이상), iOS(11 이상) 및 Android API 21 이상(v5 'Lollipop')과 호환됩니다.

IronPrint C#의 System.Printing과 어떻게 다른가요?

IronPrint 단순성에 중점을 둔 크로스 플랫폼 솔루션을 제공하는 반면, System.Printing은 Windows 기반 애플리케이션을 위한 기본 통합 및 제어 기능을 제공합니다.

IronPrint 사용하여 사용 가능한 네트워크 프린터 목록을 어떻게 확인할 수 있습니까?

IronPrint 에서 Printer.GetPrinterNames() 메서드를 사용하면 사용 가능한 프린터 드라이버 목록을 얻을 수 있습니다.

IronPrint 에서 사용할 수 있는 고급 인쇄 옵션에는 어떤 것들이 있습니까?

IronPrint 용지 크기, 용지 방향, DPI, 복사 매수, 프린터 이름, 용지 여백 및 회색조를 포함한 고급 설정을 지원합니다.

IronPrint 에 사용할 수 있는 라이선스 옵션은 무엇인가요?

IronPrint 라이선스는 구매하거나 Iron Software 웹사이트에서 30일 무료 평가판을 신청할 수 있습니다. 라이선스 키는 애플리케이션의 appSettings.json 파일에 저장됩니다.

명령줄을 통해 IronPrint 설치하는 데 사용되는 명령어는 무엇입니까?

명령줄을 통해 IronPrint 설치하려면 Install-Package IronPrint 명령을 사용하십시오.

커티스 차우
기술 문서 작성자

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

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

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me