C#에서 PDF 생성에 사용자 정의 하이픈 삽입하는 방법
C# PDF 생성에서의 사용자 정의 하이픈 삽입은 좁은 열, 송장, 계약 및 다언어 보고서에서 어색한 간격, 단어 넘침, 부적절한 텍스트 줄 바꿈 등을 해결하는 데 도움이 됩니다. PDF 렌더러가 올바른 하이픈 패턴을 적용하지 않으면, 정렬된 텍스트가 큰 간격을 남기거나 줄을 넘어 부적절하게 구분될 수 있습니다.
IronPDF에서는 HTML에서 PDF로 렌더링할 때 Word 스타일의 문서 객체 모델을 사용하는 대신 Chromium 엔진을 통해 하이픈이 처리됩니다. CSS hyphens: auto 속성은 렌더러가 올바른 음절 경계에서 단어를 자를 수 있게 하며, IronPDF는 PDF 생성 중 이 동작을 적용합니다. ChromePdfRenderOptions의 CustomHyphenation 속성은 어떤 하이픈 패턴을 사용할지 제어합니다.
패턴 파일은 TeX 형식을 사용하며 로컬 파일 경로 또는 원격 URL에서 로드될 수 있습니다. 이로 인해 다양한 언어 및 문서 레이아웃에 맞춰 사용자 정의 하이픈 규칙을 정의할 수 있으며, 최종 PDF에서 더욱 세부적으로 단어 끊기를 제어할 수 있습니다.
이 가이드는 C#에서 CustomHyphenationDefinitions API를 사용하는 방법을 설명하며, 로컬 및 원격 패턴 로딩, 대체 동작, 제한 사항, 오류 처리, 캐싱 등이 포함됩니다.
-
1Install IronPDF with NuGet Package Manager
-
2다음 코드 조각을 복사하여 실행하세요.
using IronPdf; // Create renderer and assign custom hyphenation patterns from a remote URL var renderer = new ChromePdfRenderer(); renderer.RenderingOptions.CustomHyphenation = new CustomHyphenationDefinitions { PatternSource = "https://raw.githubusercontent.com/hyphenation/tex-hyphen/master/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/hyph-en-us.pat.txt", ExceptionSource = "https://raw.githubusercontent.com/hyphenation/tex-hyphen/master/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/hyph-en-us.hyp.txt" }; // Render HTML with CSS hyphens:auto to trigger word breaking var pdf = renderer.RenderHtmlAsPdf("<div style='text-align:justify; hyphens:auto; width:120px;'>Supercalifragilisticexpialidocious</div>"); pdf.SaveAs("hyphenated.pdf");C# -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
무료 체험판으로 오늘 프로젝트에서 IronPDF 사용 시작하기
최소 워크플로우
- IronPDF NuGet 패키지 설치
renderer인스턴스 생성renderer.CustomHyphenation에PatternSource경로나 URL이 있는 새CustomHyphenationDefinitions설정- HTML 콘텐츠의 CSS에
hyphens포함 renderer.RenderHtmlAsPdf()호출 후 결과 저장
PDF 렌더링에서 사용자 정의 하이픈이 어떻게 작동하는가?
CustomHyphenationDefinitions 클래스는 IronPDF가 렌더링 과정에서 하이픈 규칙을 로드하는 위치를 정의합니다. Chromium 엔진은 이러한 패턴을 읽고 HTML 요소에 CSS hyphens 규칙이 있을 때 이를 적용합니다.
CustomHyphenationDefinitions Class란 무엇인가?
이 클래스는 두 가지 속성을 노출합니다:
| 재산 | 유형 | 필요함 | 설명 |
|---|---|---|---|
PatternSource | 문자열 | 예 | 하이픈 패턴 파일의 경로 또는 URL (예: hyph-en-us.pat.txt) |
ExceptionSource | 문자열 | 아니요 | 하이픈 예외 파일의 경로 또는 URL (예: hyph-en-us.hyp.txt) |
패턴 파일은 GitHub의 tex-hyphen 프로젝트에서 유지 관리하는 TeX 하이픈 형식을 따릅니다. 각 언어는 리포지토리에 두 개의 파일이 있습니다: 패턴 규칙용 hyph-{lang}.pat.txt 그리고 예외 목록용 hyph-{lang}.hyp.txt. GitHub에 호스팅된 파일을 참조할 때는 원본 콘텐츠 URL(접두사 https://raw.githubusercontent.com/)이 필요합니다 — 기본 GitHub 페이지 URL은 HTML을 반환하며, 패턴 텍스트가 아닙니다.
맞춤형 하이픈이 내장 언어 설정을 덮어쓰는 경우는 무엇입니까?
PdfHyphenationLanguage enum과 ChromePdfRenderOptions에서의 HyphenationLanguage는 영어(미국식), 영어(영국식), 러시아어에 대한 내장된 프리셋을 제공합니다. CustomHyphenation 속성은 두 개의 속성 모두 설정된 경우 이 enum보다 우선됩니다. 이는 명확한 우선 순위 체인을 따릅니다:
- CustomHyphenation — 유효한
PatternSource가 설정된 경우 사용자 정의 패턴이 사용됩니다 - HyphenationLanguage — 사용자 정의 패턴이 구성되지 않은 경우, 내장 언어 프리셋 사용
- 없음 — 둘 다 설정되지 않은 경우, 하이픈이 적용되지 않습니다
사용자 정의 패턴 로드에 실패하면 어떻게 되나요?
패턴 로드 중에 발생한 오류는 기록되지만 예외를 발생시키지 않습니다. 렌더링 작업은 실패하기보다는 하이픈 없이 계속 진행됩니다. HyphenationLanguage 값도 설정된 경우 렌더러는 내장된 프리셋으로 대체합니다.
이 무음 실패 동작은 프로덕션 환경을 위한 의도적 설계 선택입니다. 원격 패턴 파일을 가져오는 도중의 네트워크 시간 초과, 잘못된 파일 경로, DNS 해상도 실패 또는 잘못된 패턴 내용은 렌더링 파이프라인을 충돌시키지 않습니다. PDF는 여전히 생성되며, 단지 하이픈 된 단어 끊기가 없을 뿐입니다.
트레이드 오프는 가시성입니다. 잘못된 패턴 파일이나 첫 번째 로드에서 도달할 수 없는 URL은 캐싱이 실패 상태도 저장되므로 동일한 소스 값을 사용하는 모든 후속 렌더링에 대해 조용히 영향을 미칩니다. 권고 사항은 패턴 파일을 검증하고 원격 URL에 대한 네트워크 액세스를 애플리케이션 시작 시 또는 CI/CD 배포 확인 중에 확인하는 것입니다 - 렌더링 시점에서가 아니라.
패턴 파일을 원격 URL에서 로드할 수 있는 방법은?
원격 URL에 PatternSource을 지정하는 것은 파일을 프로젝트에 번들로 묶지 않고도 사용자 정의 하이픈을 적용하는 가장 빠른 방법입니다. 다음 예제는 U.S. 텍스 하이픈 저장소에서 영어 패턴을 로드하고 정렬된 텍스트 블록을 렌더링합니다:
using IronPdf;
var renderer = new ChromePdfRenderer();
// Load custom patterns from a remote TeX hyphenation repository
renderer.RenderingOptions.CustomHyphenation = new CustomHyphenationDefinitions
{
PatternSource = "https://raw.githubusercontent.com/hyphenation/tex-hyphen/master/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/hyph-en-us.pat.txt",
ExceptionSource = "https://raw.githubusercontent.com/hyphenation/tex-hyphen/master/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/hyph-en-us.hyp.txt"
};
string html = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
.narrow-column {
width: 150px;
text-align: justify;
hyphens: auto;
-webkit-hyphens: auto;
border: 1px solid #ccc;
padding: 10px;
}
</style>
</head>
<body>
<div class='narrow-column'>
The extraordinarily sophisticated implementation demonstrates
how hyphenation significantly improves the typographical quality
of justified text in constrained column widths.
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("remote-hyphenation.pdf");Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Load custom patterns from a remote TeX hyphenation repository
renderer.RenderingOptions.CustomHyphenation = New CustomHyphenationDefinitions With {
.PatternSource = "https://raw.githubusercontent.com/hyphenation/tex-hyphen/master/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/hyph-en-us.pat.txt",
.ExceptionSource = "https://raw.githubusercontent.com/hyphenation/tex-hyphen/master/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/hyph-en-us.hyp.txt"
}
Dim html As String = "
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
.narrow-column {
width: 150px;
text-align: justify;
hyphens: auto;
-webkit-hyphens: auto;
border: 1px solid #ccc;
padding: 10px;
}
</style>
</head>
<body>
<div class='narrow-column'>
The extraordinarily sophisticated implementation demonstrates
how hyphenation significantly improves the typographical quality
of justified text in constrained column widths.
</div>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("remote-hyphenation.pdf")산출
렌더링된 PDF는 음절 경계에서 깨끗하게 단어가 맞는 정렬된 단락을 보여줍니다. 하이픈 처리가 없으면 동일한 텍스트가 큰 단어 간 간격을 생성하거나 열이 넘칠 수 있습니다.
Chromium 호환성을 위해 hyphens 및 hyphenate-limit-chars CSS 선언이 필요합니다. hyphens 규칙은 하이픈을 가장 두드러지게 만듭니다. 표적 HTML 요소에 CSS 선언이 없으면 커스텀 패턴은 로드되지만 적용되지 않습니다.
https://github.com/hyphenation/tex-hyphen/blob/master/...는 HTML 페이지 래퍼를 반환하며, 이는 패턴 인증에 실패할 것입니다. https://raw.githubusercontent.com/... 형식을 사용하거나 GitHub에서 "Raw" 버튼을 클릭하여 올바른 URL을 확보하십시오.원격 소스 제한은 무엇입니까?
| 제약조건 | 값 |
|---|---|
| 프로토콜 | HTTP 및 HTTPS (HTTPS 권장) |
| 허용된 콘텐츠 유형 | text/plain, application/octet-stream |
| 최대 응답 크기 | 5 MB |
| 요청 시간 초과 | 10 초 |
| 보안 | SSRF 공격을 방지하기 위해 개인/로컬 IP(10.x.x.x, 192.168.x.x, localhost)로의 요청이 차단됩니다. |
| 거부된 콘텐츠 | 이진 파일, null 바이트가 있는 파일, <script> 태그가 포함된 파일 |
컨테이너 및 클라우드 환경(Docker, Azure, AWS)은 원격 로딩이 성공하려면 패턴 파일 호스트에 대한 아웃바운드 HTTPS 액세스가 있어야 합니다.
패턴 파일을 로컬 파일에서 로드하는 방법은?
외부 네트워크 접근이 제한된 환경이나 빌드 시간 번들이 선호되는 경우, PatternSource 또한 로컬 파일 시스템 경로를 허용합니다:
hyph-en-us.pat.txt 및 hyph-en-us.hyp.txt를 다운로드하고, 코드에서 참조하는 경로에 배치하십시오.using IronPdf;
var renderer = new ChromePdfRenderer();
// Load English hyphenation patterns from local files
renderer.RenderingOptions.CustomHyphenation = new CustomHyphenationDefinitions
{
PatternSource = @"C:\patterns\hyph-en-us.pat.txt",
ExceptionSource = @"C:\patterns\hyph-en-us.hyp.txt"
};
string html = @"
<html>
<head>
<style>
.invoice-container {
width: 220px;
text-align: justify;
hyphens: auto;
-webkit-hyphens: auto;
font-family: Georgia, serif;
font-size: 11px;
line-height: 1.5;
border: 1px solid #ddd;
padding: 12px;
}
h3 { font-size: 13px; margin-top: 0; }
.terms { color: #555; margin-top: 10px; font-size: 9px; }
</style>
</head>
<body>
<div class='invoice-container'>
<h3>Invoice #20260331</h3>
<p>Nondiscrimination acknowledgement: The undersigned
representative hereby confirms that all pharmaceutical
reimbursement documentation has been independently
verified and cross-referenced against the applicable
regulatory framework established by the appropriate
governmental oversight authority.</p>
<p class='terms'>Notwithstanding any indemnification
provisions, the counterparty's disproportionate
liability shall not exceed the predetermined
recharacterization threshold established under the
intergovernmental cooperation agreement.</p>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("local-hyphenation.pdf");Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Load English hyphenation patterns from local files
renderer.RenderingOptions.CustomHyphenation = New CustomHyphenationDefinitions With {
.PatternSource = "C:\patterns\hyph-en-us.pat.txt",
.ExceptionSource = "C:\patterns\hyph-en-us.hyp.txt"
}
Dim html As String = "
<html>
<head>
<style>
.invoice-container {
width: 220px;
text-align: justify;
hyphens: auto;
-webkit-hyphens: auto;
font-family: Georgia, serif;
font-size: 11px;
line-height: 1.5;
border: 1px solid #ddd;
padding: 12px;
}
h3 { font-size: 13px; margin-top: 0; }
.terms { color: #555; margin-top: 10px; font-size: 9px; }
</style>
</head>
<body>
<div class='invoice-container'>
<h3>Invoice #20260331</h3>
<p>Nondiscrimination acknowledgement: The undersigned
representative hereby confirms that all pharmaceutical
reimbursement documentation has been independently
verified and cross-referenced against the applicable
regulatory framework established by the appropriate
governmental oversight authority.</p>
<p class='terms'>Notwithstanding any indemnification
provisions, the counterparty's disproportionate
liability shall not exceed the predetermined
recharacterization threshold established under the
intergovernmental cooperation agreement.</p>
</div>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("local-hyphenation.pdf")산출
아래에서 볼 수 있듯이, 그렇지 않으면 넘치거나 과도한 간격을 생성하는 긴 단어들이 자동으로 음절 경계에서 나누어집니다. 엔진은 필요한 경우에만 하이픈 처리합니다 - 줄에 깔끔하게 맞는 단어는 전체로 남습니다.
다른 언어로 전환하려면 파일 경로만 변경하면 됩니다:
// Switch to French hyphenation — just change the file paths
renderer.RenderingOptions.CustomHyphenation = new CustomHyphenationDefinitions
{
PatternSource = @"C:\patterns\hyph-fr.pat.txt",
ExceptionSource = @"C:\patterns\hyph-fr.hyp.txt"
};' Switch to French hyphenation — just change the file paths
renderer.RenderingOptions.CustomHyphenation = New CustomHyphenationDefinitions With {
.PatternSource = "C:\patterns\hyph-fr.pat.txt",
.ExceptionSource = "C:\patterns\hyph-fr.hyp.txt"
}CustomHyphenation는 내장 PdfHyphenationLanguage enum에서 지원하지 않는 언어에 특히 유용합니다. 현재는 영어(미국식), 영어(영국식), 러시아어만 지원됩니다.
로컬 파일 제약조건은 무엇입니까?
| 제약조건 | 값 |
|---|---|
| 허용된 확장자 | .txt, .pat |
| 최대 파일 크기 | 5 MB |
| 인코딩 | UTF-8 |
| 콘텐츠 규칙 | 유효한 하이픈 처리 패턴만 - 주석, 메타데이터, 헤더, TeX 지시어 또는 인코딩 메모 없음 |
| 거부된 콘텐츠 | 이진 파일, null 바이트가 있는 파일, <script> 태그가 포함된 파일 |
캐싱이 배치 렌더링 성능에 미치는 영향은?
사용자 지정 하이픈 패턴은 첫 로드 후 메모리에 캐시되며, PatternSource 및 ExceptionSource 값으로 키가 설정됩니다. 같은 소스 경로나 URL을 참조하는 후속 렌더링은 파일을 다시 다운로드하거나 다시 읽지 않고 캐싱된 패턴을 재사용합니다.
이 동작은 대량 PDF 렌더링 워크플로에 두 가지 실질적인 영향을 미칩니다:
성능: 첫 번째 렌더링은 I/O 비용(네트워크 요청 또는 디스크 읽기)을 부담합니다. 그 후의 모든 렌더는 패턴 로딩 관점에서 사실상 무료입니다. 동일한 하이픈 처리 설정으로 수백 개의 PDF를 생성하는 배치 작업의 경우 오버헤드는 무시할 수 있을 정도입니다.
조용한 실패 지속성: 패턴 로드 중 오류가 발생해도 예외가 발생하지 않고 렌더러가 하이픈 처리 없이 계속되므로 잘못된 패턴 파일이나 첫 번째 로드 시 네트워크 실패가 전체 배치에 걸쳐 조용히 지속됩니다. 각 후속 렌더링도 하이픈 처리가 없으며 추가적인 오류 신호는 없습니다. 애플리케이션 시작 또는 배포 시 패턴 파일을 검증하고 URL 접근 가능성을 확인하십시오 - 렌더링 시간에는 하지 마십시오.
캐시 키 정체성: 캐시 키는 PatternSource (그리고 설정된 경우 ExceptionSource)의 정확한 문자열 값입니다. 같은 URL 또는 파일 경로를 가리키는 두 렌더러 인스턴스는 동일한 캐싱된 패턴을 공유합니다. URL을 변경하면 - 같은 파일의 다른 버전이라도 - 새로 로드하게 됩니다.
프로덕션 배포 전에 파일 콘텐츠를 사전 검증하십시오. 패턴 파일은 유효한 하이픈 처리 텍스트만 포함해야 합니다. 주석, TeX 지시어, 인코딩 선언 또는 비패턴 콘텐츠의 존재는 통합을 실패하게 만듭니다. tex-hyphen 저장소는 수십 개의 언어에 대한 사전 개발된 깨끗한 패턴 파일을 제공합니다.
원격 패턴 소스에 HTTPS를 권장합니다. HTTP도 지원하지만 파일 콘텐츠에 대한 전송 계층 보호를 제공하지 않습니다.
다음 단계는 무엇인가요?
ChromePdfRenderOptions의 CustomHyphenation 속성은 TeX 패턴 파일을 지원하는 언어에 대해 단어 잘림 동작에 대한 직접적인 제어를 제공합니다 — PdfHyphenationLanguage를 통해 사용 가능한 세 가지 내장 프리셋을 넘어 확장됩니다. 패턴 파일은 원격 URL이나 로컬 경로에서 로드되며, 첫 사용 후 메모리에 캐시되고 로드가 실패하면 HyphenationLanguage 설정으로 대체합니다. 오류는 기록되지만 절대 발생하지 않으므로 패턴 검증은 렌더링 시간 대신 배포 중에 수행해야 합니다.
관련 IronPDF 렌더링 구성에 대해서는 다음을 참조하십시오:
ChromePdfRenderOptionsAPI 참조에서 사용 가능한 모든 렌더링 옵션PdfHyphenationLanguageenum에서 내장된 언어 프리셋- 전체 HTML 렌더링 파이프라인에 대한 HTML에서 PDF로 렌더링 튜토리얼
- 기타 ChromePdfRenderOptions 구성에 대한 렌더링 옵션 사용 방법
- PDF 생성 및 조작 기능의 전체 세트에 대한 IronPDF 기능 개요
IronPDF의 무료 30일 체험판을 받아 커스텀 하이픈 처리를 라이브 프로젝트에서 테스트하거나, 프로덕션 배포를 위한 라이선스 옵션을 확인하십시오.
ChromePdfRenderer PatternSource CustomHyphenationDefinitions string hyphens: auto RenderHtmlAsPdf CustomHyphenationDefinitions hyphens: auto HyphenationLanguage ChromePdfRenderOptions hyph-en-us.pat.txt -webkit-hyphens: auto text-align: justify PdfHyphenationLanguage ChromePdfRenderOptions
자주 묻는 질문
C#을 사용하여 PDF 생성에서 맞춤 하이픈 적용을 구현하려면 어떻게 해야 합니까?
IronPDF를 사용하여 PDF 생성에서 TeX 하이픈 패턴을 URL 또는 로컬 파일에서 로드함으로써 맞춤 하이픈 적용을 구현할 수 있습니다. 이를 통해 C#에서 PDF를 생성할 때 단어 분리를 제어할 수 있습니다.
TeX 하이픈 패턴이 무엇이며 IronPDF에서는 어떻게 사용됩니까?
TeX 하이픈 패턴은 적절한 하이픈 지점에서 단어를 분리하기 위한 규칙 집합입니다. IronPDF는 이러한 패턴을 로드하여 생성된 PDF에서 단어가 하이픈 처리되는 방식을 관리할 수 있도록 합니다.
IronPDF에서 URL에서 하이픈 패턴을 로드할 수 있습니까?
네, IronPDF는 URL에서 하이픈 패턴을 직접 로드하는 것을 지원하여 C# PDF 프로젝트에 동적이고 유연한 단어 분할 구성을 가능하게 합니다.
IronPDF에서 하이픈 패턴에 로컬 파일을 사용할 수 있습니까?
물론입니다. IronPDF는 로컬 파일에서 맞춤 하이픈 패턴을 로드할 수 있어 PDF에서 단어 하이픈 적용을 정확하게 제어할 수 있습니다.
IronPDF에서 맞춤 하이픈 사용 시 제약은 무엇입니까?
IronPDF에서 맞춤 하이픈을 사용할 때 패턴이 올바르게 형식화되고 해당 언어 및 문서 레이아웃 요구 사항과 일치하도록 해야 합니다.
내 PDF 문서에서 맞춤 하이픈이 왜 필요합니까?
맞춤 하이픈 적용은 PDF 문서에서 가독성을 향상시키고 일관된 서식을 보장하는 데 유용하며, 특히 복잡한 언어별 단어 분할을 처리할 때 유용합니다.
IronPDF는 맞춤 하이픈 적용을 구현하기 위한 코드 예제를 제공합니까?
네, IronPDF는 C# 프로젝트에서 맞춤 하이픈 적용을 구현하는 데 도움이 되는 코드 예제를 제공하여 이 기능을 PDF 생성 프로세스에 쉽게 통합할 수 있게 합니다.
맞춤 하이픈 적용이 PDF 생성에 어떻게 향상됩니까?
맞춤 하이픈 적용은 단어 분할을 정확하게 제어하여 문서의 외관과 가독성을 향상시켜 다양한 언어와 형식에서 문서의 매력을 높이는 데 기여합니다.

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