C#에서 사용자 지정 용지 크기로 PDF를 렌더링하는 방법
IronPDF는 ChromePdfRenderer 클래스를 사용하여 C#에서 사용자 지정 용지 크기로 PDF를 렌더링할 수 있으며, SetCustomPaperSizeInInches()과 같은 메소드를 통해 특정 크기를 설정하여 포스터나 배너와 같은 특수 레이아웃에 대한 문서 크기를 정확하게 제어할 수 있습니다.
사용자 지정 용지 크기란 A4 또는 레터 사이즈(8.5 x 11인치)와 같은 표준 크기가 아닌, 사용자가 직접 정의하는 비표준 용지 크기를 의미합니다. 맞춤 용지 크기는 포스터, 배너 또는 특수 문서와 같이 독특하거나 특정한 레이아웃이 필요한 문서를 인쇄할 때 자주 사용됩니다.
IronPDF 에서 제공하는 다양한 용지 크기를 살펴보세요. 필요에 맞는 폭넓은 선택지를 제공합니다!
빠른 시작: IronPDF 에서 사용자 지정 용지 크기 정의하기이 간편 가이드에서는 IronPDF 사용하여 단 몇 줄의 코드로 사용자 지정 용지 크기를 설정하는 방법을 알려드립니다. IronPDF 사용하면 원하는 단위로 정확한 너비와 높이 치수를 정의하여 PDF 크기를 쉽게 조정할 수 있습니다. 이러한 유연성은 포스터나 배너와 같이 독특한 레이아웃이 필요한 문서를 제작하는 데 이상적입니다. NuGet을 통해 IronPDF 라이브러리를 다운로드하고, 원하는 용지 크기를 간편하게 설정하기 위해 이 예제를 따르세요.
-
1IronPDF를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
var renderer = new IronPdf.ChromePdfRenderer { RenderingOptions = { PaperSize = IronPdf.Rendering.PdfPaperSize.Custom } }; renderer.RenderingOptions.SetCustomPaperSizeInInches(5, 7); renderer.RenderHtmlAsPdf("<h1>Custom size</h1>").SaveAs("custom-size.pdf")Dim renderer = New IronPdf.ChromePdfRenderer With {.RenderingOptions = { .PaperSize = IronPdf.Rendering.PdfPaperSize.Custom }} renderer.RenderingOptions.SetCustomPaperSizeInInches(5, 7) renderer.RenderHtmlAsPdf("<h1>Custom size</h1>").SaveAs("custom-size.pdf")Dim renderer = New IronPdf.ChromePdfRenderer With {.RenderingOptions = { .PaperSize = IronPdf.Rendering.PdfPaperSize.Custom }} renderer.RenderingOptions.SetCustomPaperSizeInInches(5, 7) renderer.RenderHtmlAsPdf("<h1>Custom size</h1>").SaveAs("custom-size.pdf") -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronPDF 사용을 시작해보세요 무료 체험
최소 워크플로우(5단계)
- PDF에서 사용자 정의 용지 크기를 설정하기 위해 NuGet에서 IronPDF 다운로드하기
- C#에서
ChromePdfRenderer클래스를 인스턴스화합니다 - 새 객체에서
RenderingOptions에 접근합니다 - 측정 단위에 따라
SetCustomPaperSize메서드 중 하나를 호출합니다. - PDF 문서를 렌더링하고 내보냅니다.
표준 용지 크기는 어떻게 사용하나요?
먼저, ChromePdfRenderer 클래스의 인스턴스를 생성합니다. 그런 다음, 새로 생성된 객체의 RenderingOptions 프로퍼티를 사용하여 PaperSize을 변경하십시오. 원하는 용지 크기를 지정하기 위해 PdfPaperSize 열거형에서 미리 정의된 값 중 하나로 설정합니다. 편의를 위해 100개 이상의 미리 정의된 표준 용지 크기를 제공합니다.
PDF 렌더링 옵션을 작업할 때, IronPDF는 문서가 형식화되는 방식을 포괄적으로 제어할 수 있게 해줍니다. 표준 용지 크기에는 A4, Letter, Legal과 같은 일반적으로 사용되는 형식과 여러 국제 표준이 포함됩니다.
사용 가능한 표준 용지 크기는 무엇입니까?
아래는 표준 용지 크기를 설정하는 방법의 예입니다.
using IronPdf;
using IronPdf.Rendering;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set paper size to A4
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Standard Paper Size</h1>");
pdf.SaveAs("standardPaperSize.pdf");using IronPdf;
using IronPdf.Rendering;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set paper size to A4
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Standard Paper Size</h1>");
pdf.SaveAs("standardPaperSize.pdf");Imports IronPdf
Imports IronPdf.Rendering
Private renderer As New ChromePdfRenderer()
' Set paper size to A4
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Standard Paper Size</h1>")
pdf.SaveAs("standardPaperSize.pdf")Imports IronPdf
Imports IronPdf.Rendering
Private renderer As New ChromePdfRenderer()
' Set paper size to A4
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Standard Paper Size</h1>")
pdf.SaveAs("standardPaperSize.pdf")IronPDF 다음과 같은 다양한 표준 용지 크기를 지원합니다.
- ISO 216 시리즈: A0에서 A10, B0에서 B10
- 북미: Letter, Legal, Tabloid, Executive
- 건축: ANSI A에서 E
- 일본: JIS B0에서 B10
- 봉투 크기: 다양한 국제 봉투 표준
사용 가능한 용지 크기와 그 치수의 전체 목록은 API 레퍼런스 문서를 참조하세요.
용지 크기를 결정하는 속성은 무엇입니까?
PaperSize: 편지를 비롯한 A3, A4 등의 미리 정의된 크기로 PDF 페이지의 출력 용지 크기를 설정합니다.ForcePaperSize: HTML에서 PDF를 생성한 후 페이지를 크기 조정하여IronPdf.ChromePdfRenderOptions.PaperSize을 통해 지정된 정확한 페이지 크기를 강제합니다. 이 기능은 용지 크기를 지정하는 CSS 규칙을 우회하는 데 유용합니다.
사용자 정의 여백과 함께 이러한 속성을 사용할 때 PDF 레이아웃을 정밀하게 제어할 수 있습니다.
다양한 단위로 된 표준 용지 크기를 어떻게 구할 수 있나요?
표준 용지 크기의 치수를 알고 싶으신가요? 이 작업은 ToMillimeters 메소드를 사용하여 쉽게 수행할 수 있습니다. 이 메소드는 Length 객체로 표준 용지 크기의 너비와 높이를 포함하는 튜플을 반환합니다. Length 클래스는 매우 유연하여 이러한 크기를 다양한 단위로 손쉽게 변환할 수 있습니다. 포함:
- 밀리미터
- 센티미터
- 인치
- 픽셀
- 포인트
using IronPdf.Rendering;
double A4WidthInPixel = PdfPaperSize.A4.ToMillimeters().width.ToPixel();
double A4HeightInCentimeter = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter();using IronPdf.Rendering;
double A4WidthInPixel = PdfPaperSize.A4.ToMillimeters().width.ToPixel();
double A4HeightInCentimeter = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter();Imports IronPdf.Rendering
Private A4WidthInPixel As Double = PdfPaperSize.A4.ToMillimeters().width.ToPixel()
Private A4HeightInCentimeter As Double = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter()Imports IronPdf.Rendering
Private A4WidthInPixel As Double = PdfPaperSize.A4.ToMillimeters().width.ToPixel()
Private A4HeightInCentimeter As Double = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter()CSS 반응형 레이아웃과 통합할 때나 사용자 정의 레이아웃에 대한 정확한 치수를 계산해야 할 때 특히 유용합니다.
사용자 지정 용지 크기는 어떻게 만드나요?
먼저, ChromePdfRenderer 클래스를 인스턴스화하여 시작합니다. 새로 생성된 객체에서 RenderingOptions에 접근하여 새로 생성된 PDF 문서에 사용자 지정 용지 크기를 적용할 수 있습니다. PDF 페이지의 출력 용지 크기를 설정하는 데 사용할 수 있는 방법은 네 가지가 있으며, 각 방법은 서로 다른 측정 단위를 기반으로 합니다.
SetCustomPaperSizeInCentimeters: 크기는centimeters단위로 표시됩니다.SetCustomPaperSizeInInches: 크기는inches단위로 표시됩니다.SetCustomPaperSizeInMillimeters: 크기는millimeters단위로 표시됩니다.SetCustomPaperSizeInPixelsOrPoints: 크기는pixels or points단위로 표시됩니다.
사용자 정의 용지 크기를 생성할 때 머리글과 바닥글 및 페이지 방향 설정과 어떻게 상호작용할지를 고려하는 것이 중요합니다.
사용자 지정 치수에 사용할 수 있는 단위는 무엇입니까?
다음은 용지 크기를 센티미터 단위로 설정하는 방법의 예입니다.
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set custom paper size in cm
renderer.RenderingOptions.SetCustomPaperSizeinCentimeters(15, 15);
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Custom Paper Size</h1>");
pdf.SaveAs("customPaperSize.pdf");using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set custom paper size in cm
renderer.RenderingOptions.SetCustomPaperSizeinCentimeters(15, 15);
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Custom Paper Size</h1>");
pdf.SaveAs("customPaperSize.pdf");Imports IronPdf
Private renderer As New ChromePdfRenderer()
' Set custom paper size in cm
renderer.RenderingOptions.SetCustomPaperSizeinCentimeters(15, 15)
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Custom Paper Size</h1>")
pdf.SaveAs("customPaperSize.pdf")Imports IronPdf
Private renderer As New ChromePdfRenderer()
' Set custom paper size in cm
renderer.RenderingOptions.SetCustomPaperSizeinCentimeters(15, 15)
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Custom Paper Size</h1>")
pdf.SaveAs("customPaperSize.pdf")다음은 각 측정 단위에 대한 추가 예시입니다.
// Example: Custom paper size in inches (for US letter-like custom size)
renderer.RenderingOptions.SetCustomPaperSizeInInches(8.5, 11.5);
// Example: Custom paper size in millimeters (for precise metric measurements)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 420); // A3 size
// Example: Custom paper size in pixels (useful for screen-based layouts)
renderer.RenderingOptions.SetCustomPaperSizeInPixelsOrPoints(1024, 768, 96); // 96 DPI// Example: Custom paper size in inches (for US letter-like custom size)
renderer.RenderingOptions.SetCustomPaperSizeInInches(8.5, 11.5);
// Example: Custom paper size in millimeters (for precise metric measurements)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 420); // A3 size
// Example: Custom paper size in pixels (useful for screen-based layouts)
renderer.RenderingOptions.SetCustomPaperSizeInPixelsOrPoints(1024, 768, 96); // 96 DPI' Example: Custom paper size in inches (for US letter-like custom size)
renderer.RenderingOptions.SetCustomPaperSizeInInches(8.5, 11.5)
' Example: Custom paper size in millimeters (for precise metric measurements)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 420) ' A3 size
' Example: Custom paper size in pixels (useful for screen-based layouts)
renderer.RenderingOptions.SetCustomPaperSizeInPixelsOrPoints(1024, 768, 96) ' 96 DPI' Example: Custom paper size in inches (for US letter-like custom size)
renderer.RenderingOptions.SetCustomPaperSizeInInches(8.5, 11.5)
' Example: Custom paper size in millimeters (for precise metric measurements)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 420) ' A3 size
' Example: Custom paper size in pixels (useful for screen-based layouts)
renderer.RenderingOptions.SetCustomPaperSizeInPixelsOrPoints(1024, 768, 96) ' 96 DPI사용자 정의 크기 작업 시, 뷰포트 및 확대/축소 설정을 탐색하여 콘텐츠가 사용자 정의 치수 내에 적합하게 맞는지 확인하는 것도 좋습니다.
용지 크기를 어떻게 수정할 수 있나요?
기존 PDF 문서 또는 새로 렌더링된 PDF에서 각 페이지의 크기는 ExtendPage 메소드를 사용하여 수정할 수 있습니다. 이 방법을 사용하면 대상 페이지 색인, 네 면 각각을 수정할 값, 측정 단위를 지정할 수 있습니다. 각 변의 값은 음수일 수도 있고, 양수일 수도 있습니다. 음수이면 해당 변이 줄어들고, 양수이면 해당 변이 늘어납니다.
이 기능은 여러 페이지 크기의 PDF 파일을 병합하거나 인쇄용 문서를 준비하는 등 PDF 파일 생성 후 수정이 필요할 때 특히 유용합니다.
ExtendPage는 어떤 매개변수를 허용합니까?
ExtendPage 메소드는 다음과 같은 매개변수를 수락합니다:
- 페이지 인덱스: 수정할 페이지의 0부터 시작하는 인덱스
- 왼쪽 확장: 왼쪽을 확장/축소할 양
- 오른쪽 확장: 오른쪽을 확장/축소할 양
- 위쪽 확장: 위쪽을 확장/축소할 양
- 하단 확장: 아래쪽을 확장/축소할 양
- 측정 단위: 측정 단위 (
millimeters, inches, etc.)
다음은 용지 크기를 수정하는 방법의 예입니다.
using IronPdf;
using IronPdf.Editing;
PdfDocument pdf = PdfDocument.FromFile("customPaperSize.pdf");
pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter);
pdf.SaveAs( "extendedLeftSide.pdf");using IronPdf;
using IronPdf.Editing;
PdfDocument pdf = PdfDocument.FromFile("customPaperSize.pdf");
pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter);
pdf.SaveAs( "extendedLeftSide.pdf");Imports IronPdf
Imports IronPdf.Editing
Private pdf As PdfDocument = PdfDocument.FromFile("customPaperSize.pdf")
pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter)
pdf.SaveAs("extendedLeftSide.pdf")Imports IronPdf
Imports IronPdf.Editing
Private pdf As PdfDocument = PdfDocument.FromFile("customPaperSize.pdf")
pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter)
pdf.SaveAs("extendedLeftSide.pdf")다음은 다양한 페이지 수정 사항을 보여주는 보다 포괄적인 예입니다.
// Extend all sides equally
pdf.ExtendPage(0, 10, 10, 10, 10, MeasurementUnit.Millimeter);
// Reduce page size (negative values)
pdf.ExtendPage(1, -20, -20, -10, -10, MeasurementUnit.Millimeter);
// Extend only top and bottom (useful for adding header/footer space)
pdf.ExtendPage(2, 0, 0, 25, 25, MeasurementUnit.Millimeter);
// Work with inches instead of millimeters
pdf.ExtendPage(3, 0.5, 0.5, 1, 1, MeasurementUnit.Inch);// Extend all sides equally
pdf.ExtendPage(0, 10, 10, 10, 10, MeasurementUnit.Millimeter);
// Reduce page size (negative values)
pdf.ExtendPage(1, -20, -20, -10, -10, MeasurementUnit.Millimeter);
// Extend only top and bottom (useful for adding header/footer space)
pdf.ExtendPage(2, 0, 0, 25, 25, MeasurementUnit.Millimeter);
// Work with inches instead of millimeters
pdf.ExtendPage(3, 0.5, 0.5, 1, 1, MeasurementUnit.Inch);' Extend all sides equally
pdf.ExtendPage(0, 10, 10, 10, 10, MeasurementUnit.Millimeter)
' Reduce page size (negative values)
pdf.ExtendPage(1, -20, -20, -10, -10, MeasurementUnit.Millimeter)
' Extend only top and bottom (useful for adding header/footer space)
pdf.ExtendPage(2, 0, 0, 25, 25, MeasurementUnit.Millimeter)
' Work with inches instead of millimeters
pdf.ExtendPage(3, 0.5, 0.5, 1, 1, MeasurementUnit.Inch)' Extend all sides equally
pdf.ExtendPage(0, 10, 10, 10, 10, MeasurementUnit.Millimeter)
' Reduce page size (negative values)
pdf.ExtendPage(1, -20, -20, -10, -10, MeasurementUnit.Millimeter)
' Extend only top and bottom (useful for adding header/footer space)
pdf.ExtendPage(2, 0, 0, 25, 25, MeasurementUnit.Millimeter)
' Work with inches instead of millimeters
pdf.ExtendPage(3, 0.5, 0.5, 1, 1, MeasurementUnit.Inch)맞춤형 용지 크기 제작을 위한 모범 사례
IronPDF 에서 사용자 지정 용지 크기를 사용할 때는 다음과 같은 모범 사례를 고려하십시오.
- 다양한 단위 테스트: 사용자 정의 크기를 작업할 때, 어느 측정 단위가 사용 사례에 가장 잘 맞는지 테스트하세요. 픽셀은 화면 레이아웃에 적합하지만, 밀리미터나 인치는 인쇄에 더 적합합니다.
- 인쇄 여백 고려: 인쇄를 위한 PDF를 생성할 때 프린터 여백을 고려하세요. 대부분의 프린터는 용지 가장자리까지 인쇄할 수 없습니다.
- 반응형 디자인: HTML을 PDF로 변환할 때, HTML이 다양한 용지 크기에 적응할 수 있도록 반응형 디자인 원칙을 사용하세요.
- 성능 최적화: 매우 큰 사용자 정의 용지 크기는 성능에 영향을 줄 수 있습니다. 대형 문서에 대해서는 압축을 사용하는 것을 고려하세요.
- 호환성: 사용자 정의 크기의 PDF가 비표준 치수를 사용하고 있을 경우, 여러 PDF 뷰어에서 테스트하여 호환성을 보장하세요.
당신이 할 수 있는 다른 일들을 알아볼 준비가 되셨나요? 우리의 튜토리얼 페이지를 여기에서 확인해보세요: PDF 생성하기
자주 묻는 질문
IronPDF를 사용하여 C#에서 사용자 정의 용지 크기의 PDF를 어떻게 생성하나요?
IronPDF의 ChromePdfRenderer 클래스를 사용하여 사용자 지정 용지 크기를 가진 PDF를 생성할 수 있습니다. SetCustomPaperSizeInInches() 메서드를 활용하면 포스터나 배너와 같은 독특한 레이아웃에 적합한 원하는 용지 크기를 달성하기 위해 인치 단위로 정확한 치수를 설정할 수 있습니다.
IronPDF에서 사용자 정의 용지 크기에 사용할 수 있는 측정 단위는 무엇인가요?
IronPDF는 인치, 센티미터, 밀리미터 및 픽셀을 포함한 다양한 단위로 사용자 지정 용지 크기를 설정할 수 있게 합니다. SetCustomPaperSizeInInches(), SetCustomPaperSizeInCentimeters()와 같은 메서드를 사용하여 선호하는 단위에 따라 용지 크기를 정의하세요.
IronPDF로 기존 PDF의 용지 크기를 수정할 수 있나요?
네, IronPDF의 ExtendPage 메서드를 사용하여 기존 PDF의 용지 치수를 수정할 수 있습니다. 이 메서드는 연장하거나 줄일 양과 측정 단위를 지정하여 페이지의 각 측면을 조정할 수 있게 합니다.
IronPDF에서 사용자 정의 용지 크기를 사용하는 HTML을 PDF로 변환하려면 어떻게 하나요?
IronPDF에서 사용자 지정 용지 크기를 사용하여 HTML을 PDF로 변환하려면, SetCustomPaperSizeInInches()와 같은 메서드를 사용하여 원하는 용지 레이아웃을 정의한 다음 RenderHtmlAsPdf() 메서드를 사용하여 지정된 치수로 HTML 콘텐츠를 PDF로 변환합니다.
IronPDF는 표준 용지 크기를 지원하나요, 그리고 그것을 설정하는 방법은 무엇인가요?
네, IronPDF는 100개 이상의 표준 용지 크기를 지원합니다. ChromePdfRenderer 클래스의 RenderingOptions.PaperSize 속성에 액세스하고 PdfPaperSize 열거형에서 사전 정의된 값을 할당하여 표준 용지 크기를 설정할 수 있습니다. 예를 들어 A4 또는 Letter입니다.
IronPDF에서 `ForcePaperSize` 옵션의 목적은 무엇인가요?
IronPDF의 ForcePaperSize 옵션은 HTML에서 PDF를 생성한 후 페이지의 크기를 조정하여 페이지 크기가 정확히 지정된 대로 되도록 보장합니다. 이는 다른 용지 크기를 지정할 수 있는 CSS 규칙을 무시하여 PDF 치수의 일관성을 제공합니다.
다양한 PDF 뷰어에서 사용자 정의 용지 크기를 호환되게 하려면 어떻게 해야 하나요?
다양한 PDF 뷰어에서 호환성을 갖추기 위해 여러 뷰어에서 사용자 정의 크기의 PDF를 테스트하고, 크기가 PDF 표준을 준수하는지 확인하세요. 또한 인쇄 준비가 된 문서에는 프린터 여백 같은 요소도 고려하세요.
IronPDF에서 인쇄를 위한 사용자 정의 용지 크기를 설정할 때 무엇을 고려해야 하나요?
인쇄를 위한 사용자 지정 용지 크기를 설정할 때 대부분의 프린터가 테두리까지 인쇄할 수 없기 때문에 프린터 여백을 고려하십시오. 밀리미터나 인치와 같은 적절한 단위를 사용하고, 생성 후 조정이 필요한 경우 ExtendPage 메서드를 사용하여 치수를 확인하십시오.
IronPDF에서 표준 용지 크기를 다양한 단위로 변환하는 방법은 무엇인가요?
IronPDF의 ToMillimeters 메서드를 사용하여 표준 용지 크기를 다양한 단위로 변환할 수 있습니다. 이 메서드는 너비와 높이를 Length 객체로 제공하여 밀리미터, 센티미터, 인치, 픽셀 또는 포인트로 쉽게 변환할 수 있습니다.
IronPDF에서 사용자 정의 용지 크기를 사용할 때의 모범 사례는 무엇인가요?
모범 사례에는 적합성을 위한 다양한 단위 테스트, 인쇄 여백 고려, HTML을 PDF로 변환 시 반응형 디자인 사용, 매우 큰 크기에 대한 성능 최적화, 다양한 PDF 뷰어 간의 호환성 테스트 등이 포함됩니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.