C#でIronPDFを使用してPDFにヘッダーとフッターを追加する方法

C#とIronPDFを使ってPDFにヘッダーとフッターを追加する

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

IronPDF を使用すると、(単純なテキスト用)、または および を使用します。 この強力な機能は、一貫したブランディング、ページ番号、文書メタデータを持つプロフェッショナルなPDFを作成するために不可欠です。

PDFドキュメントの各ページの上部または下部にページ番号、会社のロゴ、日付を含める必要がありますか? IronPDFはC#プロジェクトでPDFにヘッダーとフッターを簡単に適用することができます。 レポート、請求書、その他のビジネス文書の作成にかかわらず、ヘッダーとフッターは、文書の使いやすさを向上させる重要なナビゲーションと識別の要素となります。

クイックスタート: C# で PDF にヘッダーとフッターを追加する

C#でIronPDFを使用して、PDFドキュメントにヘッダーとフッターを簡単に追加できます。 このガイドでは、ページ番号やカスタムテキストを含むテキストベースのヘッダーとフッターを数秒で適用する方法を示します。 および メソッドを使用すると、PDFのプレゼンテーションを素早く強化できます。 コードを最小限にして更新されたPDFを保存し、ドキュメントをプロフェッショナルに仕上げます。

  1. IronPDF をNuGetパッケージマネージャでインストール

    PM > Install-Package IronPdf
  2. このコード スニペットをコピーして実行します。

    new IronPdf.ChromePdfRenderer { RenderingOptions = { TextHeader = new IronPdf.TextHeaderFooter { CenterText = "Report • {date}" }, TextFooter = new IronPdf.TextHeaderFooter { RightText = "Page {page} of {total-pages}" } } }
        .RenderHtmlAsPdf("<h1>Hello World!</h1>")
        .SaveAs("withHeadersFooters.pdf");
  3. 実際の環境でテストするためにデプロイする

    今日プロジェクトで IronPDF を使い始めましょう無料トライアル

    arrow pointer

テキストヘッダー/フッターを追加するにはどうすればよいですか?

テキストのみのヘッダー/フッターを作成するには、オブジェクトをインスタンス化し、任意のテキストを追加して、そのオブジェクトを PDF に追加します。 クラスを使用すると、ドキュメントの全ページに一貫性のあるテキスト要素を簡単に追加できます。 この方法は、複雑なフォーマットやスタイリングを必要としないシンプルなヘッダーやフッターに特に有効です。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-add-textheaderfooter.cs
using IronPdf;

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

// Create text header
TextHeaderFooter textHeader = new TextHeaderFooter
{
    CenterText = "This is the header!",
};

// Create text footer
TextHeaderFooter textFooter = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

// Add text header and footer to the PDF
pdf.AddTextHeaders(textHeader);
pdf.AddTextFooters(textFooter);

pdf.SaveAs("addTextHeaderFooter.pdf");
Imports IronPdf

' Instantiate renderer and create PDF
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

' Create text header
Dim textHeader As New TextHeaderFooter With {
    .CenterText = "This is the header!"
}

' Create text footer
Dim textFooter As New TextHeaderFooter With {
    .CenterText = "This is the footer!"
}

' Add text header and footer to the PDF
pdf.AddTextHeaders(textHeader)
pdf.AddTextFooters(textFooter)

pdf.SaveAs("addTextHeaderFooter.pdf")
$vbLabelText   $csharpLabel

レンダリング中にヘッダー/フッターを追加するにはどうすればよいですか?

あるいは、レンダラーの `` を使用して、ヘッダーやフッターを直接追加することも可能です。 これは、レンダリングプロセス中にテキストのヘッダーとフッターを追加するもので、PDF作成後に追加するよりも効率的です。 この方法は、ヘッダーとフッターの内容が事前に分かっている場合に推奨されます。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-render-with-textheaderfooter.cs
using IronPdf;

// Instantiate renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Create header and add to rendering options
renderer.RenderingOptions.TextHeader = new TextHeaderFooter
{
    CenterText = "This is the header!",
};


// Create footer and add to rendering options
renderer.RenderingOptions.TextFooter = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

// Render PDF with header and footer
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");
pdf.SaveAs("renderWithTextHeaderFooter.pdf");
Imports IronPdf

' Instantiate renderer
Dim renderer As New ChromePdfRenderer()

' Create header and add to rendering options
renderer.RenderingOptions.TextHeader = New TextHeaderFooter With {
    .CenterText = "This is the header!"
}

' Create footer and add to rendering options
renderer.RenderingOptions.TextFooter = New TextHeaderFooter With {
    .CenterText = "This is the footer!"
}

' Render PDF with header and footer
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")
pdf.SaveAs("renderWithTextHeaderFooter.pdf")
$vbLabelText   $csharpLabel

テキストと分割のプロパティをカスタマイズするにはどうすればよいですか?

`` クラスでは、左、中央、右の位置にテキストを設定できます。 さらに、テキストのフォントタイプとサイズをカスタマイズし、関連するプロパティを設定してカスタムカラーの区切り線を追加することができます。 これらのカスタマイズオプションにより、企業ブランディングや文書スタイルガイドラインに合ったヘッダーやフッターを作成できます。 特に、ヘッダー/フッターとメインコンテンツを視覚的に分離するために、区切り線の機能が役立ちます。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-textheaderfooter-options.cs
using IronPdf;
using IronPdf.Font;
using IronSoftware.Drawing;

// Create text header
TextHeaderFooter textHeader = new TextHeaderFooter
{
    CenterText = "Center text", // Set the text in the center
    LeftText = "Left text", // Set left-hand side text
    RightText = "Right text", // Set right-hand side text
    Font = IronSoftware.Drawing.FontTypes.ArialBoldItalic, // Set font
    FontSize = 16, // Set font size
    DrawDividerLine = true, // Draw Divider Line
    DrawDividerLineColor = Color.Red, // Set color of divider line
};
Imports IronPdf
Imports IronPdf.Font
Imports IronSoftware.Drawing

' Create text header
Private textHeader As New TextHeaderFooter With {
	.CenterText = "Center text",
	.LeftText = "Left text",
	.RightText = "Right text",
	.Font = IronSoftware.Drawing.FontTypes.ArialBoldItalic,
	.FontSize = 16,
	.DrawDividerLine = True,
	.DrawDividerLineColor = Color.Red
}
$vbLabelText   $csharpLabel

カスタマイズされたテキストヘッダーはどのようなものですか?

左、中央、右のテキスト配置オプションを示すテキスト配置の例

デフォルトで利用可能なフォントはどれですか?

デフォルトで使用可能なフォントタイプを確認するには、IronPDF APIリファレンスをご覧ください。 IronPDFはArial、Times New Roman、Helvetica、Courier、およびそれらのバリエーションを含む幅広い標準フォントをサポートしています。 カスタムフォントが必要な場合は、IronPDFでのフォント管理について詳細をご覧ください。

テキストのヘッダー/フッターの余白を設定するにはどうすればよいですか?

デフォルトでは、IronPDFのテキストヘッダーとフッターにはあらかじめ定義された余白があります。 テキストヘッダーをPDF文書の全幅に表示したい場合は、余白の値を0に指定してください。これは、関数内でマージンを直接設定するか、 内の `` を通じて設定することで実現できます。 マージンコントロールを理解することは、ピクセルパーフェクトなレイアウトを実現するために非常に重要です。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-textheaderfooter-margins.cs
using IronPdf;

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

TextHeaderFooter header = new TextHeaderFooter
{
    CenterText = "This is the header!",
};

TextHeaderFooter footer = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

pdf.AddTextHeaders(header, 35, 30, 25); // Left Margin = 35, Right Margin  = 30, Top Margin = 25
pdf.AddTextFooters(footer, 35, 30, 25); // Margin values are in mm
Imports IronPdf

' Instantiate renderer and create PDF
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

Dim header As New TextHeaderFooter With {
    .CenterText = "This is the header!"
}

Dim footer As New TextHeaderFooter With {
    .CenterText = "This is the footer!"
}

pdf.AddTextHeaders(header, 35, 30, 25) ' Left Margin = 35, Right Margin = 30, Top Margin = 25
pdf.AddTextFooters(footer, 35, 30, 25) ' Margin values are in mm
$vbLabelText   $csharpLabel

レンダリング オプションでマージンを適用するにはどうすればよいですか?

に余白の値を追加すると、これらの余白はヘッダーとフッターにも適用されます。 このアプローチでは、ヘッダー、フッター、メインコンテンツなど、ドキュメント全体の余白を一元管理できます。 より高度なマージンのカスタマイズについては、カスタムマージンの設定に関するガイドをご覧ください。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-rendering-options-margins.cs
using IronPdf;

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();

TextHeaderFooter header = new TextHeaderFooter
{
    CenterText = "This is the header!",
};

TextHeaderFooter footer = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

// Margin values are in mm
renderer.RenderingOptions.MarginRight = 30;
renderer.RenderingOptions.MarginLeft = 30;
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;

// Add header and footer to renderer
renderer.RenderingOptions.TextHeader = header;
renderer.RenderingOptions.TextFooter = footer;

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");
Imports IronPdf

' Instantiate renderer and create PDF
Private renderer As New ChromePdfRenderer()

Private header As New TextHeaderFooter With {.CenterText = "This is the header!"}

Private footer As New TextHeaderFooter With {.CenterText = "This is the footer!"}

' Margin values are in mm
renderer.RenderingOptions.MarginRight = 30
renderer.RenderingOptions.MarginLeft = 30
renderer.RenderingOptions.MarginTop = 25
renderer.RenderingOptions.MarginBottom = 25

' Add header and footer to renderer
renderer.RenderingOptions.TextHeader = header
renderer.RenderingOptions.TextFooter = footer

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")
$vbLabelText   $csharpLabel

なぜ `` を使用すべきではないのですか?

オブジェクトの プロパティは、このユースケースには適していません。 これは、ヘッダー、フッター、メインコンテンツに同じ余白値を適用するため、ヘッダーがドキュメント本文と重なる可能性があります。 このプロパティは、主に `` メソッドを使用して、既存の PDF にヘッダーとフッターを適用するために使用されます。 レイアウトを管理しやすくするために、改ページを使用してコンテンツの流れを管理することを検討してください。

ダイナミック マージン サイジングとは何ですか?

ヘッダーコンテンツが文書間で異なる場合、静的な余白が問題となります。 ヘッダーとフッターの余白だけでなく、異なるヘッダーとフッターのサイズに対応するため、メインのHTMLの余白も調整する必要がありました。 そのため、コンテンツに応じてヘッダーとフッターの高さが動的に調整され、それに応じてメインのHTMLの位置が変更される、ダイナミック・マージン・サイジング機能を実装しました。 この機能は、レスポンシブCSSレイアウトを使用する場合に特に役立ちます。 この機能を試すには、以下のコードを使用してください:

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-dynamic-marigns.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = @"<div style='background-color: #4285f4; color: white; padding: 15px; text-align: center;'>
                    <h1>Example header</h1> <br>
                    <p>Header content</p>
                    </div>",
    // Enable the dynamic height feature
    MaxHeight = HtmlHeaderFooter.FragmentHeight,
};

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>");
pdf.SaveAs("dynamicHeaderSize.pdf");
Imports IronPdf

Private renderer As New ChromePdfRenderer()

renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
	.HtmlFragment = "<div style='background-color: #4285f4; color: white; padding: 15px; text-align: center;'>
                    <h1>Example header</h1> <br>
                    <p>Header content</p>
                    </div>",
	.MaxHeight = HtmlHeaderFooter.FragmentHeight
}

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>")
pdf.SaveAs("dynamicHeaderSize.pdf")
$vbLabelText   $csharpLabel
Icon Quote related to ダイナミック マージン サイジングとは何ですか?

私のお気に入りのこの種のライブラリはIronPDFです。PDFファイルの迅速で効率的な操作が可能です。また、PDF/A形式へのエクスポートやPDF文書へのデジタル署名といった多くの貴重な機能も備えています。

Milan Jovanovic related to ダイナミック マージン サイジングとは何ですか?

Milan Jovanovic

Microsoft MVP

ケーススタディを見る
Icon Quote related to ダイナミック マージン サイジングとは何ですか?

IronOCRのおかげで私たちは年間$40,000を手作業の処理から節約し、生産性を向上させ、高影響のタスクにリソースを充てることができます。非常にお勧めします。

Brent Matzelle related to ダイナミック マージン サイジングとは何ですか?

Brent Matzelle

最高技術責任者, OPYN

ケーススタディを見る
Icon Quote related to ダイナミック マージン サイジングとは何ですか?

IronSuiteは私たちの業務において重要な役割を果たしています。これらは、フロアプランの作成や在庫管理の改善を含め、ビジネス全体の効率を向上させるツールです。

David Jones related to ダイナミック マージン サイジングとは何ですか?

David Jones

リードソフトウェアエンジニア、Agorus Build

ケーススタディを見る

テキストヘッダー/フッターにメタデータを追加するにはどうすればよいですか?

テキストにプレースホルダ文字列を組み込むことで、ページ番号、日付、PDFタイトルなどのメタデータを簡単に追加できます。 これらのプレースホルダーは、PDFがレンダリングされるときに自動的に対応する値に置き換えられます。 この機能は、ドキュメントのプロパティに基づいて自動的に更新される動的なヘッダーとフッターを作成するために不可欠です。 利用可能なすべてのメタデータオプションはこちらです:

  • ``: 現在のページ番号。
  • ``: 総ページ数。
  • ``: PDFドキュメントがレンダリングされたWeb URL。
  • ``: 現在の日付。
  • ``: 現在の時刻。
  • : HTMLのタグで指定されたHTMLタイトル。
  • ``: PDF メタデータで指定された PDF タイトル。

どのプレースホルダを最も頻繁に使うべきですか?

および について詳しくは、IronPDF ページ番号ガイドをご覧ください。 これらのプレースホルダーは、重要なナビゲーション情報を提供するため、最も一般的に使用されています。 日付と時刻のプレースホルダは、レポートや請求書など、タイムスタンプの追跡が必要な文書で特に役立ちます。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-mail-merge.cs
using IronPdf;

// Create header and footer
TextHeaderFooter textHeader = new TextHeaderFooter
{
    CenterText = "{page} of {total-pages}",
    LeftText = "Today's date: {date}",
    RightText = "The time: {time}",
};

TextHeaderFooter textFooter = new TextHeaderFooter
{
    CenterText = "Current URL: {url}",
    LeftText = "Title of the HTML: {html-title}",
    RightText = "Title of the PDF: {pdf-title}",
};
Imports IronPdf

' Create header and footer
Private textHeader As New TextHeaderFooter With {
	.CenterText = "{page} of {total-pages}",
	.LeftText = "Today's date: {date}",
	.RightText = "The time: {time}"
}

Private textFooter As New TextHeaderFooter With {
	.CenterText = "Current URL: {url}",
	.LeftText = "Title of the HTML: {html-title}",
	.RightText = "Title of the PDF: {pdf-title}"
}
$vbLabelText   $csharpLabel

HTMLヘッダー/フッターを追加するにはどうすればよいですか?

HTMLとCSSを使用して、ヘッダー/フッターをさらにカスタマイズできます。 HTMLヘッダー/フッターを作成するには、クラスを使用してください。 このアプローチでは、ヘッダーとフッターに画像、複雑なレイアウト、スタイル付きコンテンツを含めることができ、最大限の柔軟性を提供します。 CSSスタイルシートからCSSスタイルを引き継ぐ場合は、クラスプロパティでLoadStylesAndCSSFromMainHtmlDocument = true`` を設定してください。 これは、ウェブフォントやアイコンを使用する場合に特に役立ちます。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-htmlheaderfooter.cs
using IronPdf;

string headerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>";

string footerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>";

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

// Create header and footer
HtmlHeaderFooter htmlHeader = new HtmlHeaderFooter
{
    HtmlFragment = headerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

HtmlHeaderFooter htmlFooter = new HtmlHeaderFooter
{
    HtmlFragment = footerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

// Add to PDF
pdf.AddHtmlHeaders(htmlHeader);
pdf.AddHtmlFooters(htmlFooter);
Imports IronPdf

Private headerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>"

Private footerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>"

' Instantiate renderer and create PDF
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

' Create header and footer
Private htmlHeader As New HtmlHeaderFooter With {
	.HtmlFragment = headerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

Private htmlFooter As New HtmlHeaderFooter With {
	.HtmlFragment = footerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

' Add to PDF
pdf.AddHtmlHeaders(htmlHeader)
pdf.AddHtmlFooters(htmlFooter)
$vbLabelText   $csharpLabel

HTMLのヘッダー/フッターの余白をコントロールするにはどうすればよいですか?

テキストのヘッダーやフッターと同様に、および メソッドには、あらかじめ定義された余白が適用されています。 カスタム余白を適用するには、指定された余白値を使用して関数のオーバーロードを使用します。 余白なしでコンテンツ全体をカバーするには、オーバーロード関数の余白を0に設定します。このレベルのコントロールは、特定のレイアウト要件を持つプロフェッショナルなドキュメントを作成する際に不可欠です。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-htmlheaderfooter-margins.cs
// Add to PDF
pdf.AddHtmlHeaders(header, 0, 0, 0);
pdf.AddHtmlFooters(footer, 0, 0, 0);
' Add to PDF
pdf.AddHtmlHeaders(header, 0, 0, 0)
pdf.AddHtmlFooters(footer, 0, 0, 0)
$vbLabelText   $csharpLabel

レンダリング中に HTML ヘッダー/フッターを追加できますか?

ヘッダーやフッターの追加は、レンダラーの `` を通じて直接行うことも可能です。 これは、レンダリング処理中にHTMLヘッダーとフッターを追加するもので、後処理よりも効率的です。 この方法は、HTMLファイルからPDFを生成したり、URLからPDFに変換したりする場合に特に役立ちます。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-htmlheaderfooter.cs
using IronPdf;

string headerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>";

string footerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>";

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

// Create header and footer
HtmlHeaderFooter htmlHeader = new HtmlHeaderFooter
{
    HtmlFragment = headerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

HtmlHeaderFooter htmlFooter = new HtmlHeaderFooter
{
    HtmlFragment = footerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

// Add to PDF
pdf.AddHtmlHeaders(htmlHeader);
pdf.AddHtmlFooters(htmlFooter);
Imports IronPdf

Private headerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>"

Private footerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>"

' Instantiate renderer and create PDF
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

' Create header and footer
Private htmlHeader As New HtmlHeaderFooter With {
	.HtmlFragment = headerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

Private htmlFooter As New HtmlHeaderFooter With {
	.HtmlFragment = footerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

' Add to PDF
pdf.AddHtmlHeaders(htmlHeader)
pdf.AddHtmlFooters(htmlFooter)
$vbLabelText   $csharpLabel

テキストとHTMLのヘッダー/フッターはいつ使い分けるべきですか?

ヘッダー/フッターをテキストとHTMLのどちらにするか決めるときは、トレードオフを考慮してください。 PDFのレンダリングを速く優先する場合は、テキストヘッダー/フッターを選びましょう。 カスタマイズ性とスタイリングが不可欠な場合は、HTMLヘッダー/フッターを選択してください。 テキストとHTMLのヘッダー/フッターのレンダリング時間の差は、HTMLのヘッダー/フッターに限られたコンテンツが含まれている場合、最小限に抑えられます。 ただし、HTMLヘッダー/フッターのサイズやアセット数が増えるにつれて、翻訳量は増加します。

パフォーマンスにはどのような影響がありますか?

テキストのヘッダー/フッターは、HTMLの解析やCSSの処理が不要なため、レンダリングが速くなります。 HTMLヘッダー/フッターは、より柔軟性がありますが、複雑さに比例してレンダリング時間が増えます。 大きな文書やバッチ処理を扱う場合、パフォーマンスの違いが顕著になります。 大量のシナリオで最適なパフォーマンスを得るには、非同期PDF生成に関するガイドをご検討ください。

次に何ができるのかを見てみましょうか? チュートリアルのページはこちらをご覧ください:PDFを作成する

よくある質問

C# で PDF にテ キ ス ト のヘ ッ ダ と フ ッ タ を追加す る には?

IronPDFでは、AddTextHeadersメソッドとAddTextFootersメソッドを使ってテキストヘッダーとフッターを追加することができます。TextHeaderFooterオブジェクトをインスタンス化し、必要なテキストを追加し、PDFに適用するだけです。これにより、すべてのページにわたってページ番号や文書タイトルのような一貫性のあるテキスト要素を追加する簡単な方法が提供されます。

PDFのヘッダーやフッターにページ番号を入れることはできますか?

はい、IronPDFは特別なプレースホルダーを使った動的なページ番号付けをサポートしています。TextHeaderFooterオブジェクトで、現在のページ番号には{page}を、総ページ数には{total-pages}を使用できます。例えば、RightText = "{page}の{total-pages}" と設定すると、自動的に各ページに正しいページ番号が表示されます。

CSSスタイリングでHTMLベースのヘッダーとフッターを追加することは可能ですか?

もちろんです!IronPDFはAddHtmlHeadersとAddHtmlFootersメソッドを提供し、完全なCSSスタイリングサポートでHTMLコンテンツを追加することができます。これにより、フォーマットされたテキスト、画像、カスタムスタイルを持つ複雑なヘッダーやフッターを作成することができます。

PDFにヘッダーとフッターを追加する最も効率的な方法は何ですか?

最も効率的な方法は、IronPDFのRenderingOptionsを使ってレンダリングプロセス中にヘッダーとフッターを追加することです。レンダリング前にChromePdfRendererでTextHeaderとTextFooterプロパティを設定することで、PDF作成後に追加するよりも処理時間を短縮できます。

ヘッダー/フッターの左、中央、右のセクションに異なるコンテンツを追加できますか?

はい、IronPDFのTextHeaderFooterクラスはLeftText、CenterText、RightTextプロパティを提供し、各セクションに異なるコンテンツを配置することができます。これにより、左側に日付、中央にタイトル、右側にページ番号のような情報を柔軟に整理することができます。

PDFのヘッダーに会社のロゴを追加するにはどうすればよいですか?

PDFのヘッダーに会社のロゴを追加するには、IronPDFのAddHtmlHeadersメソッドを使用します。HTMLコンテンツにロゴファイルを指す画像タグを記述し、CSSでスタイリングや配置を追加することで、ロゴを必要な位置に正確に表示することができます。

PDFのヘッダーとフッターに日付を含めることはできますか?

はい、IronPDFはTextHeaderFooterオブジェクトの{date}プレースホルダーを使った動的な日付挿入に対応しています。ヘッダーやフッターのテキストに{date}を含めると、PDFが生成されるときに自動的に現在の日付に置き換えられます。

How do I detect if a header or footer overlaps existing PDF content?

Pass a ContentOverlapBehavior to the AddHtmlHeaders or AddHtmlFooters overloads, or set RenderingOptions.HeaderFooterOverlapBehavior. Ignore skips the check (default), Warn logs the affected page indexes, and Throw raises an InvalidOperationException before stamping. Detection is report-only and covers text and images only, not vector content such as table borders, and it requires the HtmlHeaderFooter.MaxHeight to be set.

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 20,296,129 | バージョン: 2026.7 リリースされたばかり
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package IronPdf
サンプルを実行するHTML が PDF に変換されるのを確認します。