C#에서 인쇄를 위한 용지 여백 설정 방법

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

인쇄 여백은 문서 콘텐츠와 물리적 페이지 가장자리 사이의 빈 공간을 제어합니다. 이를 올바르게 설정하면 잘려진 텍스트를 방지하고, 프린터 간에 일관된 레이아웃을 보장하며, 송장, 보고서 및 법적 문서에 대한 형식 요구 사항을 충족합니다.

IronPrint의 Margins 클래스는 밀리미터 단위의 값을 받아들이며, uniform, horizontal/vertical, per-side의 세 가지 생성자 오버로드를 제공하므로 한 줄의 코드만으로 어떤 레이아웃 요구 사항도 충족할 수 있습니다. 아래에서는 설치부터 사용자 지정 여백을 적용한 인쇄에 이르기까지 각 접근 방식을 단계별로 살펴보겠습니다.

빠른 시작: 용지 여백 설정

  1. NuGet을 통해 IronPrint 설치: Install-Package IronPrint
  2. 파일에 using IronPrint;를 추가하십시오
  3. PrintSettings 객체 생성
  4. Margins 값을 PaperMargins에 할당하십시오(단위: 밀리미터).
  5. 파일 경로를 사용하여 Printer.Print()에 설정을 전달합니다.
  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronPrint 설치하기

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

    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);
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

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

    arrow pointer

모든 측면에 균등한 여백을 설정하는 방법은?

가장 간단한 생성자는 단일 정수를 받아 네 측면 모두에 균등하게 적용합니다. 우리는 값을 밀리미터 단위로 전달합니다:

: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)
$vbLabelText   $csharpLabel

Margins(20)Left, Top, RightBottom를 각각 20mm로 설정합니다. 이것은 모든 가장자리에서 일관된 여백을 가지는 표준 비즈니스 문서에 가장 일반적으로 선택됩니다.

IronPrint는 여백을 밀리미터 단위로 측정하므로, 인치의 100분의 1 단위를 사용하는 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)
$vbLabelText   $csharpLabel

매개변수 순서는 left, top, right, bottom입니다. 각 값은 독립적이므로 헤더, 푸터, 바인딩 가장자리 또는 천공홀 공간을 수용하는 비대칭 레이아웃을 만들 수 있습니다. Margins 클래스 API 레퍼런스 문서에는 모든 필드가 상세히 설명되어 있습니다.

일반적인 여백 레이아웃을 위한 단축 옵션은 무엇입니까?

IronPrint의 Margins 클래스는 전체 버전과 면별 버전 외에도 두 가지 추가 생성자를 제공합니다:

수평/수직 약어Margins(int horizontal, int vertical)는 left+right를 첫 번째 값으로, top+bottom을 두 번째 값으로 설정합니다:

: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)
$vbLabelText   $csharpLabel

여백 없음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 = new Margins(0)
};

// 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 = New Margins(0)
}

' Print the poster
Printer.Print("poster.png", borderless)
$vbLabelText   $csharpLabel

대부분의 물리적 프린터는 하드웨어 최소 인쇄 가능 영역을 적용한다는 것을 염두에 두세요. Margins.Zero를 설정하면 드라이버에 여백 0 설정 지시가 전송되지만, 프린터의 성능에 따라 가장자리 근처의 내용이 잘릴 수 있습니다.

여백을 다른 인쇄 설정과 어떻게 결합합니까?

PaperMarginsPrintSettings의 속성 중 하나입니다. 우리는 종이 크기, 방향, 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)
$vbLabelText   $csharpLabel

비동기 워크플로(WPF, MAUI 또는 ASP.NET 웹 앱)의 경우, UI 스레드가 차단되는 것을 방지하기 위해 Printer.Print()await Printer.PrintAsync()로 대체하십시오. 동일한 PrintSettings 객체가 두 메서드 모두에서 작동합니다.

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

IronPrint를 사용하여 인쇄 여백을 설정하는 네 가지 방법을 다루었습니다: Margins(int)를 사용한 균일한 여백, Margins(int, int, int, int)를 사용한 면별 제어, Margins(int, int)를 사용한 가로/세로 약어, 그리고 Margins.Zero를 사용한 테두리 없음 인쇄입니다. 각 접근 방식은 PrintSettings.PaperMargins에 반영되며, Printer.Print()Printer.PrintAsync() 모두와 호환됩니다.

추가 읽기를 위해 이 리소스를 탐색하세요:

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

자주 묻는 질문

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 애플리케이션과 원활하게 통합될 수 있어, 다양한 프로젝트 및 워크플로에 사용자 정의 인쇄 여백 설정을 포함시킬 수 있습니다.

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

시작할 준비 되셨나요?
Nuget 다운로드 41,154 | 버전: 2026.5 just released
Still Scrolling Icon

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

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