このガイドでは、C# での CustomHyphenationDefinitions API の使用方法について、ローカルおよびリモートのパターン読み込み、フォールバック動作、制限事項、エラー処理、キャッシュなどを含めて説明します。
NuGetでインストール
PM > Install-Package IronPdf
Install-Package IronPdf
Install IronPDF by running the command above in the NuGet Package Manager Console, or search for the package in the NuGet Package Manager.
クイックスタート
1Install IronPDF with NuGet Package Manager
PM > Install-Package IronPdf
Install-Package IronPdf
2このコード スニペットをコピーして実行します。
using IronPdf;// Create renderer and assign custom hyphenation patterns from a remote URLvar 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 breakingvar pdf = renderer.RenderHtmlAsPdf("<div style='text-align:justify; hyphens:auto; width:120px;'>Supercalifragilisticexpialidocious</div>");pdf.SaveAs("hyphenated.pdf");
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");
using IronPdf;var renderer = new ChromePdfRenderer();// Load custom patterns from a remote TeX hyphenation repositoryrenderer.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");
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");
ImportsIronPdfDim renderer As New ChromePdfRenderer()' Load custom patterns from a remote TeX hyphenation repositoryrenderer.RenderingOptions.CustomHyphenation = New CustomHyphenationDefinitionsWith { .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 AsString = "<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")
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")
using IronPdf;var renderer = new ChromePdfRenderer();// Load English hyphenation patterns from local filesrenderer.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>なしndiscrimination 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'>なしtwithstanding 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");
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>なしndiscrimination 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'>なしtwithstanding 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");
// Switch to French hyphenation — just change the file pathsrenderer.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
{
PatternSource = @"C:\patterns\hyph-fr.pat.txt",
ExceptionSource = @"C:\patterns\hyph-fr.hyp.txt"
};
' Switch to French hyphenation — just change the file pathsrenderer.RenderingOptions.CustomHyphenation = New CustomHyphenationDefinitionsWith { .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"
}
Can custom hyphenation be used with local files in IronPDF?
Yes, IronPDF supports using local file paths for hyphenation patterns, allowing environments without network access to apply custom word-breaking rules using the `CustomHyphenationDefinitions` property.
Why might one use custom hyphenation over built-in settings in IronPDF?
Custom hyphenation provides flexibility for languages not covered by IronPDF's built-in presets or when specific documents require tailored hyphenation rules to optimize layout and readability.