IRONSOFTWAREHOME
HTMLヘッダー & フッターを追加
using IronPdf;
using System;

// Instantiate Renderer
var renderer = new IronPdf.ChromePdfRenderer();


// Build a footer using html to style the text
// mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
    MaxHeight = 15, //millimeters
    HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
    DrawDividerLine = true
};

// Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25; //mm


// Build a header using an image asset
// Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    MaxHeight = 20, //millimeters
    HtmlFragment = "<img src='logo.png'>",
    BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri
};

// Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25; //mm
Imports IronPdf
Imports System

' Instantiate Renderer
Dim renderer = New IronPdf.ChromePdfRenderer()

' Build a footer using html to style the text
' mergeable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With {
    .MaxHeight = 15, 'millimeters
    .HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
    .DrawDividerLine = True
}

' Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25 'mm

' Build a header using an image asset
' Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
    .MaxHeight = 20,  'millimeters
    .HtmlFragment = "<img src='logo.png'>",
    .BaseUrl = New Uri("C:\assets\images\").AbsoluteUri
}

' Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25 'mm
NuGet Download
PM > Install-Package IronPdf
HTMLヘッダー & フッターを追加

HTMLヘッダー & フッターを追加

HTMLヘッダーとフッターは、PDFドキュメント用の動的なヘッダーとフッターを作成するための柔軟な方法を提供します。 この方法でヘッダーとフッターを追加することにより、開発者はヘッダーとフッターの外観を完全にコントロールできます。これらは独立したHTMLドキュメントとしてレンダリングされ、それぞれ独自のアセットとスタイルシートを含むことができます。

IronPDFでPDFにカスタムHTMLヘッダーとフッターを追加する手順

まず初めに、ChromePdfRenderer クラスのインスタンスを作成する必要があります。このクラスはHTMLコンテンツをピクセル完璧なPDFドキュメントにレンダリングします。

次に、HtmlHeaderFooter クラスを使用してフッターを定義します。ここでは、MaxHeight、ページ番号が含まれるHTMLコンテンツ、画像解像度の基準URLを指定します。 フッターは中央にページ情報を表示するようにスタイリングされています。

フッターとPDFのメインコンテンツの重なりを避けるために、MarginBottom プロパティを使用して下部余白を設定します。 同様に、HtmlHeaderFooter クラスを使用して画像(ロゴなど)を含むヘッダーを作成します。 ここでは、画像アセットが含まれるディレクトリへのBaseUrl を設定し、レンダリング中に適切な画像解像度を可能にしています。

最後に、MarginTop プロパティを使用して上部余白を設定し、ヘッダーとコンテンツの重なりを防ぎます。 この例は、IronPDFを使用してPDFドキュメントにカスタムHTMLヘッダーとフッターを実装するのがいかに簡単であるかを示しています。

IronPDFでPDFにHTMLヘッダーとフッターを追加する方法を学ぶ
GitHubで見る

準備はできましたか?

Nuget Downloads 21,105,021バージョン:2026.9リリースされたばかり

Key in blue circle

無料の30日間トライアルキーをすぐに入手してください。

Your trial license will be sent to your email address

制限なし。100% ロック解除済み。クレジットカード不要。

OR
bullet_checkedクレジットカードやアカウントの作成は不要です。制限なし。100% ロック解除済み。クレジットカード不要。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
無料のライブデモを予約する
Booking Badge

世界中の数百万人のエンジニアから信頼されています。

ライセンスはより安く
義務のない相談を受ける
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
世界中の数百万人のエンジニアから信頼されています。
ライセンスはより安く
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。
PDF用C# NuGetライブラリ
NuGetでインストール

バージョン: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. ソリューションエクスプローラーで参照を右クリックし、NuGetパッケージを管理を選択
  2. ブラウズを選択し、"IronPDF"を検索
  3. パッケージを選択してインストール
C# PDF DLL
DLLをダウンロード

バージョン: 2026.9

またはここからWindowsインストーラーをダウンロードする。

  1. IronPDFを~/Libsなどの場所に解凍し、ソリューションディレクトリ内に配置する
  2. Visual Studioソリューションエクスプローラーで参照を右クリックし、"IronPDF.dll"をブラウズして選択

ライセンスは$999から