Search Results for

    Show / Hide Table of Contents

    Class HtmlHeaderFooter

    A HTML Header or Footer which will be printed onto every page of the PDF. This can be used to override

    When using HtmlHeaderFooter it is important to set HtmlFragment

    Merge meta-data into your HTML using any of these placeholder strings: {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}

    Inheritance
    System.Object
    TextHeaderFooter
    HtmlHeaderFooter
    Implements
    System.ICloneable
    Inherited Members
    TextHeaderFooter.CenterText
    TextHeaderFooter.DrawDividerLine
    TextHeaderFooter.DrawDividerLineColor
    TextHeaderFooter.Font
    TextHeaderFooter.FontSize
    TextHeaderFooter.LeftText
    TextHeaderFooter.RightText
    Namespace: IronPdf
    Assembly: IronPdf.dll
    Syntax
    public class HtmlHeaderFooter : TextHeaderFooter, ITextHeaderFooter

    Full HTML rendering in PDF headers and footers becomes available through HtmlHeaderFooter. Assign any HTML snippet to HtmlFragment and IronPDF stamps it across every page of the output document, giving you pixel-accurate control over fonts, images, tables, and brand colours that plain-text headers cannot achieve. The class extends TextHeaderFooter, so it slots directly into the same HtmlToPdf and PdfDocument rendering pipeline.

    HtmlFragment is the central property. Set it to a self-contained HTML string and use the built-in placeholder tokens to inject live values at render time: {page} for the current page number, {total-pages} for the document length, {date} and {time} for the render timestamp, {url} for the source URL, {html-title} for the page title, and {pdf-title} for the PDF document title. These tokens are resolved per-page, so a footer reading "Page {page} of {total-pages}" always reflects the correct values without any extra code.

    When the header or footer references external stylesheets, web fonts, or images hosted relative to the source document, set BaseUrl to the root URL or local directory path so that the renderer can resolve those resources correctly. If the main HTML document already loads a stylesheet you want to reuse in the header, set LoadStylesAndCSSFromMainHtmlDocument to true and IronPDF will carry those styles across automatically, keeping the visual language consistent without duplicating CSS.

    MaxHeight accepts a nullable integer (in millimetres) that caps how tall the header or footer region can grow. Leave it null to let the content determine the height. The constant FragmentHeight exposes the internal sentinel value used when no explicit cap is set. Clone() produces a deep copy of the configured object, which is useful when you need slightly different headers for different rendering passes without rebuilding from scratch.

    using IronPdf;
    
    var renderer = new ChromePdfRenderer();
    renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
    {
        MaxHeight = 15,
        HtmlFragment = "<div style='font-family:Arial;font-size:10px;text-align:right'>" +
                       "Page {page} of {total-pages} &nbsp;|&nbsp; {date}</div>",
        LoadStylesAndCSSFromMainHtmlDocument = false
    };
    
    using PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Annual Report</h1><p>Content here.</p>");
    pdf.SaveAs("report.pdf");

    For a broader introduction to PDF generation, visit the IronPDF documentation hub. Step-by-step guidance on stamping headers and footers is covered in the HTML header and footer how-to, and runnable snippets are available on the header and footer examples page. Licensing and trial options are on the get-started page.

    Constructors

    HtmlHeaderFooter()

    Declaration
    public HtmlHeaderFooter()

    Fields

    FragmentHeight

    When MaxHeight is set to this values, the renderer will make sure that the margins of the page are adjusted to fit the HTML fragment.

    Declaration
    public const int FragmentHeight = 2147483647
    Field Value
    Type Description
    System.Int32

    Properties

    BaseUrl

    The Base URL all URLS in the HtmlFragment will be relative to. This includes 'src' attributes on images, scripts, style-sheets and also hrefs on hyper-links.

    Note: A base URL that points to a directory should end with a slash.

    Base URL accepts file paths as well as URLS. If no BaseUrl is given, the HtmlHeaderFooter BaseUrl will be inherited from the main HTML document where possible.

    Declaration
    public string BaseUrl { get; set; }
    Property Value
    Type Description
    System.String

    HtmlFragment

    The HTML which will be used to render the Header or Footer should be an HTML snippet rather than a complete document. It may contain styles & images.

    Merge meta-data into the HtmlFragment by putting any of these placeholder strings into the text: {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}. An alternative mail-merge style using the pattern <span class='total-pages'></span> is also supported.

    HtmlFragment is a stand-alone HTML document which does not inherit styles or settings from your main HTML content unless LoadStylesAndCSSFromMainHtmlDocument is set true

    Declaration
    public string HtmlFragment { get; set; }
    Property Value
    Type Description
    System.String

    LoadStylesAndCSSFromMainHtmlDocument

    Loads style code blocks and links to CSS style sheets from the main HTML document (which provides the PDF content) into the HtmlHeaderFooter .

    By default, HTML Headers and Footers are stand- alone HTML documents with their own default styles. Setting LoadStylesAndCSSFromMainHtmlDocument to true will attempt to load all STYLE and LINK tags from the main HTML document (which renders teh PDF) into the HtmlHeaderFooter.

    If your main HTML document contains complex CSS frameworks, styles the HEAD or BODY element heavily or loads CSS from javascript then this method may not work as intended.

    This feature is not available for RenderUrlAsPdf methods. It works for RenderHtmlAsPdf, HTMLToPdf and HtmlFileToPdf conversions only.

    It is often preferable to load style sheets explicitly into your HTML Headers and Footers as STYLE and LINK tags within the HtmlFragment for granular control

    Not supported in Docker mode.

    Declaration
    public bool LoadStylesAndCSSFromMainHtmlDocument { get; set; }
    Property Value
    Type Description
    System.Boolean

    MaxHeight

    Maximum Height of the HTML Header / Footer in millimeters. This value must be set sufficiently high to display the full HTML header / footer content.

    Declaration
    public Nullable<int> MaxHeight { get; set; }
    Property Value
    Type Description
    System.Nullable<System.Int32>

    Methods

    Clone()

    Supports System.ICloneable. Creates a deep copy of this class instance.

    Declaration
    public object Clone()
    Returns
    Type Description
    System.Object

    A deep clone of this instance. Use explicit casting to convert object back to the intended type.

    Implements

    System.ICloneable

    Inherited members

    CenterText
    DrawDividerLine
    DrawDividerLineColor
    Font
    FontSize
    LeftText
    RightText
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget
    IronPDF_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronPDF