Class TextHeaderFooter
Defines PDF Header and Footer display options.
TextHeaderFooter uses a logical approach to rendering Headers and Footers for the most common use cases.
Implements
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public class TextHeaderFooter : Object, ITextHeaderFooter, ICloneable
TextHeaderFooter prints a plain-text header or footer on every page of a rendered PDF. Assign an instance to the TextHeader and TextFooter properties of a renderer's RenderingOptions. The class carries three text slots that align to the left, center, and right of the page, plus typography and divider settings.
The class suits documents where a single line of running text is enough: page numbers in a report footer, a document title across the top of every page, a timestamp on an invoice, or a URL stamp on a printed web page. Plain text renders without an HTML engine pass for the header band, which keeps output deterministic across platforms and avoids the styling drift that can appear when a fragment is composed with the body's CSS. When images, tables, or inline CSS are required, the derived HtmlHeaderFooter is the right choice.
Seven properties cover the surface in three groups. The text slots LeftText, CenterText, and RightText hold the printed strings and accept the merge fields {page}, {total-pages}, {url}, {date}, {time}, {html-title}, and {pdf-title}, which resolve during rendering. The divider settings DrawDividerLine and DrawDividerLineColor draw a horizontal rule between the header or footer and the body. The typography settings Font (a PdfFont) and FontSize (in pixels) control the rendered text. The headers and footers how-to guide walks through the full configuration, and the text headers and footers example provides a runnable script.
using IronPdf;
var renderer = new ChromePdfRenderer();
// Text header with a centered title and a divider line
renderer.RenderingOptions.TextHeader = new TextHeaderFooter
{
CenterText = "Quarterly Report {date}",
DrawDividerLine = true,
Font = IronSoftware.Drawing.FontTypes.Helvetica,
FontSize = 12
};
// Text footer with page numbers on the right and a timestamp on the left
renderer.RenderingOptions.TextFooter = new TextHeaderFooter
{
LeftText = "{date} {time}",
RightText = "Page {page} of {total-pages}",
FontSize = 10
};
// Reserve margin space so body content does not overlap the bands
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");For pagination work, the page numbers how-to covers how {page} and {total-pages} behave across appended sections, and the custom margins guide explains how MarginTop and MarginBottom reserve space so the body does not overlap the bands.
Constructors
TextHeaderFooter()
Declaration
public TextHeaderFooter()
Properties
CenterText
Sets the centered header text for the PDF document.
Merge meta-data into your header using any of these placeholder strings: {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}
Declaration
public string CenterText { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
DrawDividerLine
Adds a horizontal line divider between the header / footer and the page content on every page of the PDF document.
Declaration
public bool DrawDividerLine { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
DrawDividerLineColor
A Color of divider line DrawDividerLine
Declaration
public Color DrawDividerLineColor { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Drawing.Color |
Font
Font family IronSoftware.Drawing.FontTypes. Default is IronSoftware.Drawing.FontTypes.Helvetica
Declaration
public PdfFont Font { get; set; }
Property Value
| Type | Description |
|---|---|
| PdfFont |
FontSize
Font size in px.
Declaration
public double FontSize { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
LeftText
Sets the left hand side header text for the PDF document.
Merge meta-data into your header using any of these placeholder strings: {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}
Declaration
public string LeftText { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
RightText
Sets the right hand side header text for the PDF document.
Merge meta-data into your header using any of these placeholder strings: {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}
Declaration
public string RightText { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
Clone()
Clones this instance.
Declaration
public object Clone()
Returns
| Type | Description |
|---|---|
| System.Object | System.Object of type SimpleHeaderFooter |