C#でPDF生成にカスタムハイフネーションを追加する方法
C#でPDFを生成する際にカスタムハイフネーションを使うと、幅の狭い段組みや請求書、契約書、多言語レポートで、語間の不自然な空きや単語のはみ出し、不適切な折り返しを抑えられます。PDFレンダラーが適切なハイフネーションパターンを適用しないと、両端揃えのテキストで語間が大きく空いたり、不自然な位置で改行されたりします。
IronPDFでは、Wordのような文書オブジェクトモデルではなく、HTMLをPDFに変換する際にChromiumエンジンがハイフネーションを処理します。CSSでhyphens: autoを指定すると、PDF生成時に適切な音節の境界で単語を分割できます。使用するハイフネーションパターンは、ChromePdfRenderOptionsのCustomHyphenationプロパティで指定します。
TeX形式のパターンファイルは、ローカルファイルのパスまたはリモートURLから読み込めます。言語や文書レイアウトに合わせて独自のルールを定義し、生成したPDFで単語を分割する位置を細かく制御できます。
このガイドでは、C#でのCustomHyphenationDefinitions APIの使用方法を説明します。これには、ローカルおよびリモートパターンの読み込み、フォールバック動作、制限事項、エラーハンドリング、およびキャッシングが含まれます。
-
1IronPDF を 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");Imports IronPdf ' Create renderer and assign custom hyphenation patterns from a remote URL Dim renderer = New ChromePdfRenderer() 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" } ' Render HTML with CSS hyphens:auto to trigger word breaking Dim pdf = renderer.RenderHtmlAsPdf("<div style='text-align:justify; hyphens:auto; width:120px;'>Supercalifragilisticexpialidocious</div>") pdf.SaveAs("hyphenated.pdf")Imports IronPdf ' Create renderer and assign custom hyphenation patterns from a remote URL Dim renderer = New ChromePdfRenderer() 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" } ' Render HTML with CSS hyphens:auto to trigger word breaking Dim pdf = renderer.RenderHtmlAsPdf("<div style='text-align:justify; hyphens:auto; width:120px;'>Supercalifragilisticexpialidocious</div>") pdf.SaveAs("hyphenated.pdf") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronPDFを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー
- IronPDF NuGetパッケージをインストールします
rendererインスタンスを作成しますPatternSourceにパスまたはURLを指定した新しいCustomHyphenationDefinitionsをrenderer.RenderingOptions.CustomHyphenationに設定します- HTMLコンテンツのCSSに
hyphensを含めます renderer.RenderHtmlAsPdf()を呼び出して結果を保存します
PDFレンダリングにおけるカスタムハイフネーションの仕組み
CustomHyphenationDefinitionsクラスは、IronPDFがレンダリングプロセス中にハイフネーションルールを読み込む場所を定義します。 Chromiumエンジンはこれらのパターンを読み込み、CSSのhyphensルールがHTML要素に存在する場合に適用します。
CustomHyphenationDefinitionsクラス
このクラスには2つのプロパティがあります。
| プロパティ | タイプ | 必須 | 説明 |
|---|---|---|---|
PatternSource | string | はい | ハイフネーションパターンファイルのパスまたはURL (例: hyph-en-us.pat.txt) |
ExceptionSource | string | いいえ | ハイフネーション例外ファイルのパスまたはURL (例: hyph-en-us.hyp.txt) |
パターンファイルは、GitHubのtex-hyphenプロジェクトが管理するTeXハイフネーション形式に従います。リポジトリには言語ごとに、パターンルールを記述したhyph-{lang}.pat.txtと、例外リストを記述したhyph-{lang}.hyp.txtがあります。通常のGitHubページのURLはHTMLを返すため、ファイルを参照するにはhttps://raw.githubusercontent.com/で始まるファイルの直接URLが必要です。
カスタムハイフネーションが組み込みの言語設定を上書きする際の動作は?
ChromePdfRenderOptionsのHyphenationLanguageでは、PdfHyphenationLanguage列挙型で定義された米国英語、英国英語、ロシア語の組み込みプリセットを指定できます。両方を設定した場合はCustomHyphenationが優先されます。適用順は以下のとおりです。
- CustomHyphenation - 有効な
PatternSourceで設定されている場合には、カスタムパターンが使用されます - HyphenationLanguage - カスタムパターンが設定されていない場合、組み込みの言語プリセットが適用されます
- None - どちらも設定されていない場合、ハイフネーションは行われません
カスタムパターンの読み込みに失敗した場合の動作
パターン読み込み中のエラーはログに記録されますが、例外をスローしません。レンダリングは失敗することなく、ハイフネーションなしで続行します。 HyphenationLanguage値も設定されている場合、レンダラーはその組み込みプリセットにフォールバックします。
この動作は、本番環境でレンダリングを継続できるようにするための設計です。リモートファイルの取得時にネットワークがタイムアウトしたり、ファイルパスやパターンの内容が不正だったり、DNSの名前解決に失敗したりしても、レンダリング処理は停止しません。PDFは生成されますが、ハイフネーションによる単語の分割は行われません。
この動作には、問題に気づきにくいという欠点があります。初回の読み込み時にファイルが不正だったりURLに接続できなかったりした場合、その失敗もキャッシュされるため、同じ読み込み元を使う後続のレンダリングすべてに影響します。パターンファイルの検証とリモートURLへの接続確認は、レンダリング時ではなく、アプリケーションの起動時またはCI/CDのデプロイ時に行ってください。
リモートURLからパターンファイルを読み込む方法
PatternSourceにリモートURLを指定するのは、ファイルをプロジェクトに同梱せずにカスタムハイフネーションを適用する最も手早い方法です。以下の例では、tex-hyphenリポジトリから米国英語のパターンを読み込み、両端揃えのテキストブロックをレンダリングします。
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");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")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では、両端揃えの段落内で単語が音節の境界で分割されています。ハイフネーションを適用しない場合、同じテキストでも単語間に大きな空きができたり、段の幅からはみ出したりします。
hyphens と hyphenate-limit-chars の両方のCSS宣言がChromiumの互換性に必要です。 hyphensルールはハイフネーションを最も目立たせます。 ターゲットHTML要素にどちらのCSS宣言も存在しない場合、カスタムパターンは読み込まれますが適用されません。
https://github.com/hyphenation/tex-hyphen/blob/master/...のような)はHTMLページのラッパーを返し、これがパターンの検証に失敗します。 正しいURLを取得するには、https://raw.githubusercontent.com/...形式を使用するか、GitHubで「Raw」ボタンをクリックします。リモートソース制約とは何ですか?
| 制約 | 値 |
|---|---|
| プロトコル | HTTPおよびHTTPS(HTTPS推奨) |
| 許可されるコンテンツタイプ | text/plain, application/octet-stream |
| 最大応答サイズ | 5 MB |
| リクエストタイムアウト | 10秒 |
| セキュリティ | プライベート/ローカルIPへのリクエスト (10.x.x.x, 192.168.x.x, localhost) はSSRF攻撃を防ぐためにブロックされます |
| 受け付けないコンテンツ | バイナリファイル、ヌルバイトを含むファイル、<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");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")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
{
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"
}' 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"
}PdfHyphenationLanguage列挙型で指定できる組み込みプリセットは、現在のところ米国英語、英国英語、ロシア語に限られます。それ以外の言語にはCustomHyphenationが特に役立ちます。
ローカルファイル制約とは何ですか?
| 制約 | 値 |
|---|---|
| 許可される拡張子 | .txt, .pat |
| 最大ファイルサイズ | 5 MB |
| エンコーディング | UTF-8 |
| コンテンツルール | 有効なハイフネーションパターンのみ - コメント、メタデータ、ヘッダー、TeXディレクティブ、エンコード情報は含まれません |
| 受け付けないコンテンツ | バイナリファイル、ヌルバイトを含むファイル、<script>タグを含むファイル |
バッチレンダリングにおけるキャッシュはパフォーマンスにどのように影響しますか?
カスタムハイフネーションパターンは初回の読み込み後に、PatternSourceとExceptionSourceの値をキーとしてメモリにキャッシュされます。以降、同じパスまたはURLを指定したレンダリングでは、ファイルを再取得せずにキャッシュ済みのパターンを再利用します。
大量PDFレンダリングでは、この動作に次の2つの影響があります。
パフォーマンス: 初回のレンダリングでは、ネットワークリクエストやディスク読み込みによるI/Oコストが発生します。2回目以降はパターンの読み込みコストがほとんどかかりません。同じ設定で数百件のPDFを生成するバッチジョブでは、負荷はごくわずかです。
読み込み失敗の影響: パターンを読み込めなくても例外は発生せず、レンダラーはハイフネーションなしで処理を続けます。初回にファイルの不備やネットワーク障害があると、バッチ内の後続処理でもハイフネーションが適用されず、追加のエラー通知もありません。パターンファイルの検証とURLへの接続確認は、レンダリング時ではなく、アプリケーションの起動時やデプロイ時に行ってください。
キャッシュキー: PatternSourceの文字列と、設定されている場合はExceptionSourceの文字列がキャッシュキーになります。同じURLまたはファイルパスを参照するレンダラーは、キャッシュ済みのパターンを共有します。同じファイルの別バージョンを参照する場合でも、URLが変わると再読み込みが行われます。
本番デプロイメント前にファイル内容を事前に検証してください。 パターンファイルには有効なハイフネーションテキストのみを含める必要があります。 コメント、TeXディレクティブ、エンコーディング宣言、または非パターンコンテンツが存在すると、統合が失敗します。 tex-hyphenリポジトリは多数の言語用に不要な記述を含まない既製のパターンファイルを提供します。
リモートパターンソースにはHTTPSを推奨します。 HTTPはサポートされていますが、ファイルコンテンツのトランスポートレイヤー保護を提供しません。
次のステップ
ChromePdfRenderOptionsのCustomHyphenationプロパティを使用すると、PdfHyphenationLanguageの3つの組み込みプリセットに加え、TeXパターンファイルが対応する言語で単語の分割を制御できます。パターンファイルはリモートURLまたはローカルパスから読み込まれ、初回使用後にメモリにキャッシュされます。読み込みに失敗すると、HyphenationLanguageの設定にフォールバックします。エラーはログに記録されますが、例外は発生しないため、パターンの検証はレンダリング時ではなくデプロイ時に行ってください。
関連するIronPDFレンダリング構成については、以下を参照してください:
- 利用可能なすべてのレンダリングオプションは、
ChromePdfRenderOptionsAPIリファレンスで確認できます - 組み込みの言語プリセットは、
PdfHyphenationLanguage列挙型で確認できます - HTMLからPDFへのレンダリングチュートリアルで完全なHTMLレンダリングパイプラインを参照します
- レンダリングオプションのハウツーで他のChromePdfRenderOptions設定を確認します
- IronPDF機能概要でPDF生成と操作機能の全セットを確認します
実際のプロジェクトでカスタムハイフネーションを試すには、IronPDFの30日間無料トライアルを利用してください。本番環境に導入する場合は、ライセンスオプションを確認してください。
ChromePdfRendererPatternSourceCustomHyphenationDefinitionsstringhyphens: auto``RenderHtmlAsPdfCustomHyphenationDefinitionshyphens: autoHyphenationLanguageChromePdfRenderOptionshyph-en-us.pat.txt-webkit-hyphens: auto``text-align: justifyPdfHyphenationLanguageChromePdfRenderOptions
よくある質問
C# PDF生成でのカスタムハイフネーションとは何ですか?
C# PDF生成でのカスタムハイフネーションは、IronPDFを使用して特定のドキュメントレイアウトや狭い列におけるテキストの折り返しと間隔を改善するための単語の改行を制御します。HTMLからPDFへのレンダリングプロセスでCSSとTeXハイフネーションパターンを利用します。
IronPDFはカスタムハイフネーションをどのように処理しますか?
IronPDFはChromePdfRenderOptions内のCustomHyphenationDefinitionsクラスを通じてカスタムハイフネーションを処理します。これにより、ローカルファイルやリモートURLからハイフネーションパターンを読み込み、Chromiumエンジンを使用したレンダリングプロセスで適用します。
IronPDFでカスタムハイフネーションパターンを使用する利点は何ですか?
IronPDFでカスタムハイフネーションパターンを使用することで、PDFのタイポグラフィーの品質を向上させるために単語の改行を精密に制御できます。これは特に多言語のドキュメントや狭いレイアウト制約のあるドキュメントに対して有益です。
IronPDFはハイフネーションパターンにリモートURLを使用できますか?
はい、IronPDFはリモートURLからカスタムハイフネーションパターンを読み込むことができ、プロジェクトにファイルを埋め込まずに動的なパターンソースを可能にします。GitHubが提供するような生のコンテンツURLが必要です。
カスタムハイフネーションパターンの読み込みに失敗した場合はどうなりますか?
IronPDFでカスタムハイフネーションパターンの読み込みが失敗した場合、エラーはログされますが例外としてスローされません。IronPDFは構成されているHyphenationLanguageにフォールバックするか、ハイフネーションなしでレンダリングを継続しようとします。
キャッシュはIronPDFでのカスタムハイフネーションにどのように影響しますか?
キャッシュは、最初に使用された後にメモリ内にロードされたハイフネーションパターンを保存します。これにより、バッチ操作のパフォーマンスが向上しますが、最初の読み込みが失敗した場合、エラーが静かに持続する可能性があります。有効なパターンファイルとURLアクセスをレンダー時間前に確認することをお勧めします。
IronPDFを使用するためにURLとパターンコンテンツをどのように検証すべきですか?
検証は、起動時または配備時に行うべきです。URLのアクセス可能性を確認し、IronPDFでのハイフネーションパターンの読み込み中に静かな失敗を避けるために、パターンファイルの有効な内容をテストします。
IronPDFでハイフネーション用にリモートURLを使用する際の制約は何ですか?
制約には、HTTP/HTTPSプロトコルの使用、最大5 MBのレスポンスサイズが含まれており、セキュリティ上の理由からプライベートIPへのリクエストは禁止されています。許可されるのは、text/plainおよびapplication/octet-streamのコンテンツタイプのみです。
IronPDFでローカルファイルを使用してカスタムハイフネーションを行うことができますか?
はい、IronPDFはローカルファイルパスをハイフネーションパターンに使用することをサポートしており、ネットワークアクセスのない環境にもCustomHyphenationDefinitionsプロパティを使ってカスタムワードブレイキングルールを適用できます。
IronPDFのビルトイン設定ではなくカスタムハイフネーションを使用する理由は何ですか?
カスタムハイフネーションは、IronPDFのビルトインプリセットでカバーされていない言語や、特定のドキュメントで適したハイフネーションルールが必要な場合に柔軟性を提供し、レイアウトと可読性を最適化します。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。