C#에서 인쇄를 위한 용지 여백 설정 방법
인쇄 여백은 문서 콘텐츠와 물리적 페이지 가장자리 사이의 빈 공간을 제어합니다. 이를 올바르게 설정하면 잘려진 텍스트를 방지하고, 프린터 간에 일관된 레이아웃을 보장하며, 송장, 보고서 및 법적 문서에 대한 형식 요구 사항을 충족합니다.
IronPrint의 Margins 클래스는 밀리미터 단위로 값을 받아들이며 세 가지 생성자 오버로드 — 균일, 수평/수직, 사이드 별 — 을 제공하여 단일 라인으로 모든 레이아웃 요구 사항을 충족시킬 수 있습니다. 설치부터 사용자 정의 여백으로 인쇄까지 각 접근 방식을 아래에서 안내합니다.
빠른 시작: 용지 여백 설정
- NuGet을 통해 IronPrint 설치:
Install-Package IronPrint - 파일에
using IronPrint;추가 PrintSettings객체 생성Margins값을PaperMargins에 할당 (값은 밀리미터 단위)- 설정을 파일 경로와 함께
Printer.Print()에 전달
-
NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronPrint 설치하기
-
다음 코드 조각을 복사하여 실행하세요.
using IronPrint; // Set 15 mm margins on all sides and print PrintSettings settings = new PrintSettings(); settings.PaperMargins = new Margins(15); Printer.Print("report.pdf", settings); -
실제 운영 환경에서 테스트할 수 있도록 배포하세요.
무료 체험판으로 오늘 프로젝트에서 IronPrint 사용 시작하기
최소 워크플로우(5단계)
- IronPrint C# 인쇄 라이브러리 설치
PrintSettings객체 생성PaperMargins에Margins값을 할당- 설정을
Printer.Print()에 전달 - 사용자 정의 여백으로 인쇄하기 위해 프로젝트 실행
모든 측면에 균등한 여백을 설정하는 방법은?
가장 간단한 생성자는 단일 정수를 받아 네 측면 모두에 균등하게 적용합니다. 우리는 값을 밀리미터 단위로 전달합니다:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-uniform-margins.cs
using IronPrint;
// Configure a uniform 20 mm margin on all sides
PrintSettings settings = new PrintSettings
{
PaperMargins = new Margins(20),
PaperSize = PaperSize.A4
};
// Print the invoice
Printer.Print("invoice.pdf", settings);
Imports IronPrint
' Configure a uniform 20 mm margin on all sides
Dim settings As New PrintSettings With {
.PaperMargins = New Margins(20),
.PaperSize = PaperSize.A4
}
' Print the invoice
Printer.Print("invoice.pdf", settings)
Margins(20)은 Left, Top, Right, Bottom을 각각 20mm로 설정합니다. 이것은 모든 가장자리에서 일관된 여백을 가지는 표준 비즈니스 문서에 가장 일반적으로 선택됩니다.
IronPrint는 밀리미터 단위로 여백을 측정하여 수십분의 인치로 사용하는 System.Drawing.Printing.Margins 클래스의 혼란을 방지합니다. IronPrint에서 25.4mm 여백은 new System.Drawing.Printing.Margins(100)와 동등하며, 변환 수학이 필요하지 않습니다.
각 측면에 다른 여백을 설정하는 방법은?
문서의 상단에 편지 머리글을 위한 공간이 더 필요하거나 하단에 바닥글을 위한 공간이 필요할 때, 우리는 네 매개 변수 생성자를 사용합니다.
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-per-side-margins.cs
using IronPrint;
// Configure per-side margins (left, top, right, bottom)
PrintSettings settings = new PrintSettings
{
PaperMargins = new Margins(10, 25, 10, 20),
PaperOrientation = PaperOrientation.Portrait
};
// Print the letterhead
Printer.Print("letterhead.pdf", settings);
Imports IronPrint
' Configure per-side margins (left, top, right, bottom)
Dim settings As New PrintSettings With {
.PaperMargins = New Margins(10, 25, 10, 20),
.PaperOrientation = PaperOrientation.Portrait
}
' Print the letterhead
Printer.Print("letterhead.pdf", settings)
매개변수 순서는 left, top, right, bottom입니다. 각 값은 독립적이므로 헤더, 푸터, 바인딩 가장자리 또는 천공홀 공간을 수용하는 비대칭 레이아웃을 만들 수 있습니다. Margins 클래스 API 참조는 모든 필드를 문서화합니다.
일반적인 여백 레이아웃을 위한 단축 옵션은 무엇입니까?
IronPrint의 Margins 클래스는 균일하고 사이드 별 이외에 추가적인 생성자를 제공합니다:
수평/수직 약칭 — Margins(int horizontal, int vertical)은 왼쪽 + 오른쪽을 첫 번째 값으로, 상단 + 하단을 두 번째 값으로 설정합니다:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-shorthand-margins.cs
using IronPrint;
// Configure horizontal and vertical margin shorthand
PrintSettings settings = new PrintSettings
{
PaperMargins = new Margins(10, 20)
};
// Print the landscape report
Printer.Print("report-landscape.pdf", settings);
Imports IronPrint
' Configure horizontal and vertical margin shorthand
Dim settings As New PrintSettings With {
.PaperMargins = New Margins(10, 20)
}
' Print the landscape report
Printer.Print("report-landscape.pdf", settings)
제로 여백 — Margins.Zero은 테두리 없는 인쇄를 위해 모든 여백을 제거합니다:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-zero-margins.cs
using IronPrint;
// Configure zero margins for edge-to-edge printing
PrintSettings borderless = new PrintSettings
{
PaperMargins = Margins.Zero
};
// Print the poster
Printer.Print("poster.png", borderless);
Imports IronPrint
' Configure zero margins for edge-to-edge printing
Dim borderless As New PrintSettings With {
.PaperMargins = Margins.Zero
}
' Print the poster
Printer.Print("poster.png", borderless)
대부분의 물리적 프린터는 하드웨어 최소 인쇄 가능 영역을 적용한다는 것을 염두에 두세요. Margins.Zero을 설정하면 드라이버에 제로 여백 지침을 전송하지만, 프린터의 기능에 따라 가장자리 근처의 콘텐츠를 여전히 잘라낼 수 있습니다.
여백을 다른 인쇄 설정과 어떻게 결합합니까?
PrintSettings에 있는 한 가지 속성인 PaperMargins. 우리는 종이 크기, 방향, DPI, 복사본 수, 그레이스케일 모드 및 프린터 선택을 단일 구성 객체에 결합할 수 있습니다:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-combined-settings.cs
using IronPrint;
// Configure full print settings with asymmetric margins
PrintSettings settings = new PrintSettings
{
PaperMargins = new Margins(15, 20, 15, 25),
PaperSize = PaperSize.A4,
PaperOrientation = PaperOrientation.Portrait,
Dpi = 300,
NumberOfCopies = 2,
Grayscale = false,
PrinterName = "HP LaserJet Pro MFP M428"
};
// Print the Q4 report to the named printer
Printer.Print("Q4-report.pdf", settings);
Imports IronPrint
' Configure full print settings with asymmetric margins
Dim settings As New PrintSettings With {
.PaperMargins = New Margins(15, 20, 15, 25),
.PaperSize = PaperSize.A4,
.PaperOrientation = PaperOrientation.Portrait,
.Dpi = 300,
.NumberOfCopies = 2,
.Grayscale = False,
.PrinterName = "HP LaserJet Pro MFP M428"
}
' Print the Q4 report to the named printer
Printer.Print("Q4-report.pdf", settings)
비동기 워크플로우 (WPF, MAUI, 또는 ASP.NET 웹 앱)의 경우 UI 스레드를 차단하지 않도록 Printer.Print()을 await Printer.PrintAsync()로 교체합니다. 동일한 PrintSettings 객체가 두 메서드와 모두 작동합니다.
내 다음 단계는 무엇인가요?
우리는 Margins(int)을 사용한 균일한 여백, Margins(int, int, int, int)을 사용한 사이드 제어, 수평/수직 약칭 Margins(int, int), 및 테두리 없는 인쇄 Margins.Zero과 함께 IronPrint로 인쇄 여백을 구성하는 네 가지 방법을 다루었습니다. 각 접근 방식은 PrintSettings.PaperMargins에 입력되어 Printer.Print() 및 Printer.PrintAsync()와 작동합니다.
추가 읽기를 위해 이 리소스를 탐색하세요:
- 포괄적 인쇄 과정을 위한 IronPrint 튜토리얼 — 인쇄 문서.
- 해상도, 방향, 복사본 등과 관련된 인쇄 설정 사용 방법.
- 생성자 및 필드 문서를 완성한
Margins클래스 API 참조. - 모든 정적 인쇄 메서드에 대한
Printer클래스 API 참조.
무료 체험판 라이선스 받기를 통해 모든 기능을 실제 환경에서 시험하거나, 배포를 준비 중이라면 라이선스 옵션 보기.
자주 묻는 질문
IronPrint란 무엇이며 C#에서 인쇄 여백 설정에 어떻게 도움이 됩니까?
IronPrint는 C#에서 인쇄 여백을 설정하는 과정을 간소화하는 .NET 라이브러리입니다. Margins 클래스 덕분에 개발자는 균일한, 각 면별, 테두리 없는 옵션을 사용하여 인쇄 여백을 쉽게 사용자 정의할 수 있습니다.
IronPrint를 사용하여 C#에서 균일한 여백을 설정하는 방법은?
IronPrint의 Margins 클래스를 사용하면 C#에서 인쇄 시 균일한 여백을 설정할 수 있습니다. 이 클래스는 페이지의 모든 면에 동일한 여백 크기를 지정하도록 합니다.
각 페이지 면에 대해 서로 다른 여백을 설정할 수 있습니까?
네, IronPrint를 사용하여 C#에서 각 페이지 면에 대해 서로 다른 여백을 설정할 수 있습니다. Margins 클래스는 상단, 하단, 왼쪽 및 오른쪽 여백을 개별적으로 사용자 정의할 수 있는 옵션을 제공합니다.
IronPrint를 사용하여 테두리 없는 인쇄를 만들 수 있습니까?
IronPrint는 테두리 없는 인쇄를 지원합니다. Margins 클래스를 사용하여 여백을 0으로 설정하면 효과적으로 테두리가 없는 인쇄를 생성할 수 있습니다.
용지 여백 설정에 IronPrint를 사용하는 이점은 무엇입니까?
IronPrint는 C#에서 용지 여백을 설정하는 과정을 간소화하여 직관적이고 효율적인 API를 제공합니다. 해당 Margins 클래스는 코드 작성의 복잡성을 줄이고 생산성을 높이므로 사용자 정의 인쇄 요구 사항을 구현하기가 더 쉬워집니다.
IronPrint를 사용하여 인쇄 여백을 설정하려면 광범위한 코딩 지식이 필요합니까?
아니요, IronPrint를 사용하여 인쇄 여백을 설정하려면 광범위한 코딩 지식이 필요하지 않습니다. 이 라이브러리는 사용자 친화적으로 설계되어 있어 기본적인 C# 기술을 갖춘 사람도 쉽게 사용자 정의 여백을 구현할 수 있습니다.
IronPrint는 여백 설정 시 다양한 용지 크기를 어떻게 처리합니까?
IronPrint는 문서의 구체적인 크기에 맞는 여백을 지정할 수 있게 함으로써 다양한 용지 크기에 적응합니다. 이는 당신의 인쇄 출력물이 구체적은 레이아웃 필요를 충족됨을 보장합니다.
IronPrint를 다른 .NET 애플리케이션과 통합할 수 있습니까?
네, IronPrint는 다른 .NET 애플리케이션과 원활하게 통합될 수 있어, 다양한 프로젝트 및 워크플로에 사용자 정의 인쇄 여백 설정을 포함시킬 수 있습니다.

