C#에서 인쇄를 위한 용지 크기 설정 방법
IronPrint의 PrintSettings 클래스는 개발자에게 PaperSize 속성을 통해 용지 크기에 대한 직접적인 제어 권한을 제공합니다. 우리는 PaperSize 열거형에서 PaperSize.A4 또는 PaperSize.Letter 와 같은 값을 할당하고 구성된 PrintSettings 객체를 IronPrint의 인쇄 메서드에 전달합니다. 프린터는 이후 해당 작업을 위해 정확한 용지 크기를 사용합니다.
이 가이드는 표준 용지 크기를 설정하고, 크기를 다른 인쇄 설정과 결합하고, 비동기적으로 인쇄하는 방법을 C# 코드와 함께 안내합니다.
빠른 시작: 용지 크기 설정- NuGet을 통해 IronPrint 설치:
Install-Package IronPrint - 파일에
using IronPrint;추가 PrintSettings객체 생성PaperSize를PaperSize열거형의 값 (예:PaperSize.A4) 중 하나로 설정- 설정을
Printer.Print()또는Printer.PrintAsync()에 전달
-
1IronPrint를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
using IronPrint; // Print a PDF on A4 paper Printer.Print("report.pdf", new PrintSettings { PaperSize = PaperSize.A4 });Imports IronPrint ' Print a PDF on A4 paper Printer.Print("report.pdf", New PrintSettings With { .PaperSize = PaperSize.A4 })Imports IronPrint ' Print a PDF on A4 paper Printer.Print("report.pdf", New PrintSettings With { .PaperSize = PaperSize.A4 }) -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronPrint 사용을 시작해보세요 무료 체험
최소 워크플로우(5단계)
- IronPrint C# 인쇄 라이브러리 설치
PrintSettings객체 생성PaperSize열거형에서PaperSize설정- 설정을
Printer.Print()에 전달 - 선택한 용지 크기로 인쇄할 프로젝트 실행
C#에서 인쇄할 때 용지 크기 설정 방법은?
PaperSize 열거형에서 PaperSize 속성으로 값을 할당하여 PrintSettings 객체의 용지 크기를 설정합니다. 그런 다음 해당 객체를 IronPrint의 인쇄 메서드 중 하나에 전달합니다.
using IronPrint;
// Configure print settings with US Letter paper
PrintSettings settings = new PrintSettings();
settings.PaperSize = PaperSize.Letter;
// Print to the default printer
Printer.Print("invoice.pdf", settings);using IronPrint;
// Configure print settings with US Letter paper
PrintSettings settings = new PrintSettings();
settings.PaperSize = PaperSize.Letter;
// Print to the default printer
Printer.Print("invoice.pdf", settings);Imports IronPrint
' Configure print settings with US Letter paper
Dim settings As New PrintSettings()
settings.PaperSize = PaperSize.Letter
' Print to the default printer
Printer.Print("invoice.pdf", settings)Imports IronPrint
' Configure print settings with US Letter paper
Dim settings As New PrintSettings()
settings.PaperSize = PaperSize.Letter
' Print to the default printer
Printer.Print("invoice.pdf", settings)우선 PrintSettings 를 인스턴스화하여 프린터의 기본 설정으로 초기화합니다. 그런 다음 우리는 표준 8.5 × 11 인치 형식에 해당하는 PaperSize.Letter로 PaperSize 를 재정의합니다. Printer.Print 를 호출하면 IronPrint는 해당 용지 크기를 사용하여 시스템의 기본 프린터로 문서를 보냅니다.
어떤 PaperSize 도 지정되지 않은 경우, IronPrint는 운영 체제의 기본 프린터가 설정된 용지 크기 대로 PaperSize.PrinterDefault 를 사용합니다. 이는 관련 장비에 따라 프린터 구성이 다른 생산 환경에서 중요한 세부 사항입니다.
라이브러리가 지원하는 용지 크기는 무엇인가요?
PaperSize 열거형에는 ISO 국제 표준, 일반적인 미국 크기, 그리고 프린터 기본값을 포함하여 12개의 값이 들어 있습니다. 아래 표는 사용 가능한 모든 옵션을 나열합니다.
| 열거형 값 | 기준 | 치수 (mm) | 치수 (in) |
|---|---|---|---|
PaperSize.A0 | ISO A0 | 841 × 1189 | 33.1 × 46.8 |
PaperSize.A1 | ISO A1 | 594 × 841 | 23.4 × 33.1 |
PaperSize.A2 | ISO A2 | 420 × 594 | 16.5 × 23.4 |
PaperSize.A3 | ISO A3 | 297 × 420 | 11.7 × 16.5 |
PaperSize.A4 | ISO A4 | 210 × 297 | 8.3 × 11.7 |
PaperSize.A5 | ISO A5 | 148 × 210 | 5.8 × 8.3 |
PaperSize.B4 | ISO B4 | 250 × 353 | 9.8 × 13.9 |
PaperSize.B5 | ISO B5 | 176 × 250 | 6.9 × 9.8 |
PaperSize.Letter | US Letter | 216 × 279 | 8.5 × 11.0 |
PaperSize.Legal | US Legal | 216 × 356 | 8.5 × 14.0 |
PaperSize.Executive | US Executive | 184 × 267 | 7.25 × 10.5 |
PaperSize.PrinterDefault | 프린터 기본값 | 다양한 | 다양한 |
각 값은 잘 알려진 종이 표준에 직접 매핑됩니다. PrinterDefault 옵션은 IronPrint에 프린터가 현재 설정된 용지 크기를 사용하도록 지시하여 특정 형식을 강제하기보다는 최종 사용자 프린터 선호를 존중하려는 경우에 유용합니다.
전체 API 레퍼런스는 PaperSize 클래스 문서를 참조하십시오.
다른 인쇄 설정과 용지 크기를 결합하는 방법은?
PrintSettings 클래스는 PaperSize 외에도 여러 속성을 노출합니다. 배향, DPI, 여백, 복사본 수, 회색조 모드 등 모든 것을 단일 객체로 구성할 수 있습니다.
using IronPrint;
// Configure full print settings
PrintSettings settings = new PrintSettings
{
PaperSize = PaperSize.A4,
PaperOrientation = PaperOrientation.Landscape,
Dpi = 300,
NumberOfCopies = 3,
PaperMargins = new Margins(15, 15, 15, 15),
Grayscale = false
};
// Print the quarterly report
Printer.Print("quarterly-report.pdf", settings);using IronPrint;
// Configure full print settings
PrintSettings settings = new PrintSettings
{
PaperSize = PaperSize.A4,
PaperOrientation = PaperOrientation.Landscape,
Dpi = 300,
NumberOfCopies = 3,
PaperMargins = new Margins(15, 15, 15, 15),
Grayscale = false
};
// Print the quarterly report
Printer.Print("quarterly-report.pdf", settings);Imports IronPrint
' Configure full print settings
Dim settings As New PrintSettings With {
.PaperSize = PaperSize.A4,
.PaperOrientation = PaperOrientation.Landscape,
.Dpi = 300,
.NumberOfCopies = 3,
.PaperMargins = New Margins(15, 15, 15, 15),
.Grayscale = False
}
' Print the quarterly report
Printer.Print("quarterly-report.pdf", settings)Imports IronPrint
' Configure full print settings
Dim settings As New PrintSettings With {
.PaperSize = PaperSize.A4,
.PaperOrientation = PaperOrientation.Landscape,
.Dpi = 300,
.NumberOfCopies = 3,
.PaperMargins = New Margins(15, 15, 15, 15),
.Grayscale = False
}
' Print the quarterly report
Printer.Print("quarterly-report.pdf", settings)이곳에서는 명확성을 위해 객체 초기자 구문을 사용합니다. PaperOrientation 는 A4 용지를 더 넓은 축으로 회전시킵니다. 300에서의 Dpi 은 차트와 오른정밀 텍스트에 대해 선명한 출력을 보장합니다. Margins 는 Margins 생성자를 통해 최고, 오른쪽, 바닥, 왼쪽 - 총 네 개의 밀리미터 값들을 허용합니다. NumberOfCopies 속성 기본값은 1이지만 가독성을 위해 명시적으로 설정합니다.
이 속성들은 충돌 없이 함께 작동합니다. IronPrint는 구성을 검증하고 결합된 설정을 단일 인쇄 작업으로 프린터 드라이버에 전달합니다. 더 고급 설정에 대해서는 프린터 선택 및 트레이 구성과 같은, 전체 인쇄 설정 가이드를 참조하세요.
사용자 정의 용지 크기로 비동기 인쇄하는 방법은?
WPF나 WinForms 앱과 같이 주 스레드를 차단할 수 없는 애플리케이션의 경우, Printer.PrintAsync을 사용합니다. 이 메서드는 동일한 PrintSettings 객체를 수용하며 Task 를 반환합니다.
using IronPrint;
using System.Threading.Tasks;
public class DocumentPrinter
{
public async Task PrintLegalDocumentAsync(string filePath)
{
// Configure Legal paper size
PrintSettings settings = new PrintSettings
{
PaperSize = PaperSize.Legal,
PaperOrientation = PaperOrientation.Portrait,
Dpi = 300
};
// Print asynchronously
await Printer.PrintAsync(filePath, settings);
}
}using IronPrint;
using System.Threading.Tasks;
public class DocumentPrinter
{
public async Task PrintLegalDocumentAsync(string filePath)
{
// Configure Legal paper size
PrintSettings settings = new PrintSettings
{
PaperSize = PaperSize.Legal,
PaperOrientation = PaperOrientation.Portrait,
Dpi = 300
};
// Print asynchronously
await Printer.PrintAsync(filePath, settings);
}
}Imports IronPrint
Imports System.Threading.Tasks
Public Class DocumentPrinter
Public Async Function PrintLegalDocumentAsync(filePath As String) As Task
' Configure Legal paper size
Dim settings As New PrintSettings With {
.PaperSize = PaperSize.Legal,
.PaperOrientation = PaperOrientation.Portrait,
.Dpi = 300
}
' Print asynchronously
Await Printer.PrintAsync(filePath, settings)
End Function
End ClassImports IronPrint
Imports System.Threading.Tasks
Public Class DocumentPrinter
Public Async Function PrintLegalDocumentAsync(filePath As String) As Task
' Configure Legal paper size
Dim settings As New PrintSettings With {
.PaperSize = PaperSize.Legal,
.PaperOrientation = PaperOrientation.Portrait,
.Dpi = 300
}
' Print asynchronously
Await Printer.PrintAsync(filePath, settings)
End Function
End Class이 클래스 기반 예제는 프린트 로직을 감싼 DocumentPrinter 서비스를 보여주는 현실적인 패턴을 설명합니다. 계약서와 법률 서식에 표준 형식인 PaperSize.Legal (8.5 × 14 인치) 를 구성합니다. await 키워드는 IronPrint가 인쇄 작업을 처리하는 동안 호출 스레드가 반응성을 유지하도록 보장합니다.
이 메소드는 버튼 클릭 핸들러, 백그라운드 서비스 또는 async/await가 지원되는 곳 어디에서든 호출할 수 있습니다. IronPrint의 비동기 메소드 - PrintAsync 및 ShowPrintDialogAsync를 포함하여 - 동일한 PrintSettings 구성을 수락하므로, 동기 및 비동기 경로 간의 용지 크기 동작이 동일합니다.
내 다음 단계는 무엇인가요?
IronPrint의 PaperSize 열거형을 사용하여 기본 단일 속성 구성부터 결합된 설정과 비동기 인쇄까지 C#에서 용지 크기 설정 방법을 다루었습니다. PrintSettings 클래스는 용지 치수에 대한 추측을 제거하는 깔끔하고 강력하게 형식화된 API를 제공합니다.
IronPrint의 기능을 계속 탐구하려면:
- 프린터 이름, 트레이 및 회색 음영을 포함하여 모든 인쇄 설정을 구성하는 방법을 배우세요
- 일반적인 시나리오에 대한 인쇄 설정 코드 예제를 보세요
Printer,PrintSettings,PaperSize와 같은 클래스에 대한 전체 API 레퍼런스를 탐색하세요
무료 30일 체험판을 시작하여 자체 프로젝트에서 용지 크기 구성을 테스트하거나, 프로덕션 배포를 위한 라이선스 옵션을 확인하세요.
자주 묻는 질문
IronPrint를 사용하여 C#에서 특정 용지 크기를 설정하려면 어떻게 해야 하나요?
C#에서 특정 용지 크기를 설정하려면 IronPrint의 PrintSettings 클래스를 사용하세요. PaperSize 열거형에서 PaperSize.A4 또는 PaperSize.Letter와 같은 값을 PaperSize 속성에 할당하고, PrintSettings 개체를 Printer.Print 메서드에 전달하십시오.
IronPrint가 여러 용지 크기를 처리할 수 있나요?
예, IronPrint는 A4, Letter, Legal 등과 같은 표준 크기를 포함하는 PaperSize 열거형을 통해 여러 용지 크기를 지원합니다. 인쇄 요구 사항에 따라 이 중에서 선택할 수 있습니다.
IronPrint로 문서를 비동기로 인쇄할 수 있나요?
예, IronPrint는 비차단 작업을 허용하는 Printer.PrintAsync 메서드를 제공하여 WPF 또는 WinForms와 같은 애플리케이션에서 문서를 비동기로 인쇄할 수 있습니다.
IronPrint로 인쇄할 때 용지 크기를 제어하는 속성은 무엇인가요?
IronPrint를 사용할 때 용지 크기를 제어하는 속성은 PrintSettings 클래스 내의 PaperSize 속성입니다.
IronPrint가 용지 크기 외에 인쇄 설정을 사용자 지정할 수 있나요?
예, IronPrint는 방향, DPI, 여백, 복사본 수 및 그레이스케일 모드를 포함하여 PrintSettings 클래스를 통해 인쇄 설정을 추가로 사용자 정의할 수 있습니다.
IronPrint는 용지 크기가 지정되지 않은 경우 어떻게 처리하나요?
PrintSettings에 PaperSize가 지정되지 않은 경우 IronPrint는 기본 프린터에 구성된 용지 크기를 사용하는 PaperSize.PrinterDefault를 기본값으로 사용합니다.
IronPrint에서 최종 사용자 프린터 환경 설정을 존중하려면 어떻게 하나요?
PaperSize.PrinterDefault를 사용하면 IronPrint가 최종 사용자 프린터 환경 설정을 존중하며, 기본 프린터 구성에 설정된 크기를 사용합니다.
C# 프로젝트에서 IronPrint를 사용하려면 어떻게 설치하나요?
Install-Package IronPrint 명령을 통해 NuGet을 통해 IronPrint를 설치한 다음, C# 파일에서 using IronPrint;를 포함하여 기능을 액세스할 수 있습니다.
IronPrint가 지원하는 용지 크기는 무엇인가요?
IronPrint는 A0, A1, A2, A3, A4, A5와 같은 ISO 표준 및 Letter, Legal, Executive와 같은 일반 미국 크기를 포함하여 여러 용지 크기를 지원합니다.
IronPrint의 전체 API 레퍼런스는 어떻게 액세스할 수 있나요?
클래스 및 메서드에 대한 자세한 정보를 제공하는 IronSoftware 웹사이트의 문서를 통해 IronPrint의 전체 API 레퍼런스에 액세스할 수 있습니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.