IRONSOFTWAREHOME
Add HTML Headers & Footers
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
Add HTML Headers & Footers

Add HTML Headers & Footers

HTML headers and footers provide a flexible method for creating dynamic headers and footers for your PDF documents. By adding headers and footers through this method, developers have complete control over how their headers and footers look, as they are rendered as independent HTML documents capable of containing their own assets and stylesheets.

Steps to Add Custom HTML Headers and Footers in a PDF with IronPDF

To begin with, you first need to create an instance of the ChromePdfRenderer class, which handles the rendering of HTML content into a pixel-perfect PDF document.

Next, define a footer using the HtmlHeaderFooter class, where you specify the MaxHeight, HTML content for the footer (which in our case includes page numbering), and base URL for image resolution. The footer is styled to display centered page information.

To avoid overlap between the footer and the PDF's main content, set a bottom margin using the MarginBottom property. Similarly, create a header that includes an image (such as a logo) by using the HtmlHeaderFooter class. Here we have set up a BaseUrl to the directory containing your image asset, allowing for proper image resolution during rendering.

Finally, use the MarginTop property to set a top margin that prevents overlap between the header and the content. This example demonstrates how easy it is to implement custom HTML headers and footers in your PDF documents with IronPDF.

Learn to Add HTML Headers & Footers to PDFs with IronPDF
View on GitHub

Ready to Get Started?

Nuget Downloads 20,878,335Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required