HTMLヘッダー & フッターを追加
PDF 文書をレンダリングする際に、HTML ヘッダーとフッターを含むようにレンダリングオプションを設定します。 IronPDF は、PDF の高度な生成と操作を可能にする Iron Software のライブラリです。
IronPdfの柔軟なPDFレンダリングツールを使用して、ヘッダーコンテンツを区切り線、HTMLフラグメントで定義し、ヘッダーの最大高さを指定します。 同様に、IronPDF によって提供される htmlHeader プロパティを使用してフッターコンテンツを定義します。
ヘッダーとフッターの高さは自動的に検出されないため、メインの HTML コンテンツと重なる可能性があることに注意してください。 ヘッダーとフッターが適切に配置されるようにマージンをカスタマイズします。
ヘッダー、フッターの実装方法や他の機能を探索する方法の詳細については、IronPDF 公式ウェブサイトをご覧ください。
using IronPdf;
class Program
{
static void Main()
{
// Create a Renderer object for PDF creation
var renderer = new HtmlToPdf();
// Define the header content including an HTML fragment
string htmlHeader = "<div style='width:100%; border-bottom:1px solid black; text-align:center;'>Header Content</div>";
// Define the footer content including an HTML fragment
string htmlFooter = "<div style='width:100%; border-top:1px solid black; text-align:center;'>Footer Content</div>";
// Configure the header and footer with desired heights
renderer.PrintOptions.Header = new SimpleHeaderFooter()
{
HtmlFragment = htmlHeader,
MaxHeight = 50 // Set the maximum height of the header
};
renderer.PrintOptions.Footer = new SimpleHeaderFooter()
{
HtmlFragment = htmlFooter,
MaxHeight = 50 // Set the maximum height of the footer
};
// Customize page margins to prevent overlap of the header/footer with content
renderer.PrintOptions.MarginTop = 60; // Margin to accommodate the header
renderer.PrintOptions.MarginBottom = 60; // Margin to accommodate the footer
// Render HTML to PDF
var pdf = renderer.RenderHtmlAsPdf("<h1>Main Content</h1><p>This is some example content.</p>");
// Save the PDF file
pdf.SaveAs("output.pdf");
}
}using IronPdf;
class Program
{
static void Main()
{
// Create a Renderer object for PDF creation
var renderer = new HtmlToPdf();
// Define the header content including an HTML fragment
string htmlHeader = "<div style='width:100%; border-bottom:1px solid black; text-align:center;'>Header Content</div>";
// Define the footer content including an HTML fragment
string htmlFooter = "<div style='width:100%; border-top:1px solid black; text-align:center;'>Footer Content</div>";
// Configure the header and footer with desired heights
renderer.PrintOptions.Header = new SimpleHeaderFooter()
{
HtmlFragment = htmlHeader,
MaxHeight = 50 // Set the maximum height of the header
};
renderer.PrintOptions.Footer = new SimpleHeaderFooter()
{
HtmlFragment = htmlFooter,
MaxHeight = 50 // Set the maximum height of the footer
};
// Customize page margins to prevent overlap of the header/footer with content
renderer.PrintOptions.MarginTop = 60; // Margin to accommodate the header
renderer.PrintOptions.MarginBottom = 60; // Margin to accommodate the footer
// Render HTML to PDF
var pdf = renderer.RenderHtmlAsPdf("<h1>Main Content</h1><p>This is some example content.</p>");
// Save the PDF file
pdf.SaveAs("output.pdf");
}
}Imports IronPdf
Friend Class Program
Shared Sub Main()
' Create a Renderer object for PDF creation
Dim renderer = New HtmlToPdf()
' Define the header content including an HTML fragment
Dim htmlHeader As String = "<div style='width:100%; border-bottom:1px solid black; text-align:center;'>Header Content</div>"
' Define the footer content including an HTML fragment
Dim htmlFooter As String = "<div style='width:100%; border-top:1px solid black; text-align:center;'>Footer Content</div>"
' Configure the header and footer with desired heights
renderer.PrintOptions.Header = New SimpleHeaderFooter() With {
.HtmlFragment = htmlHeader,
.MaxHeight = 50
}
renderer.PrintOptions.Footer = New SimpleHeaderFooter() With {
.HtmlFragment = htmlFooter,
.MaxHeight = 50
}
' Customize page margins to prevent overlap of the header/footer with content
renderer.PrintOptions.MarginTop = 60 ' Margin to accommodate the header
renderer.PrintOptions.MarginBottom = 60 ' Margin to accommodate the footer
' Render HTML to PDF
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Main Content</h1><p>This is some example content.</p>")
' Save the PDF file
pdf.SaveAs("output.pdf")
End Sub
End Class$vbLabelText $csharpLabel
関連ドキュメントリンク
準備はできましたか?
バージョン: 2025.12 リリース




