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
Private 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,
.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,
.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
Install-Package IronPdf
Add HTML Headers & Footers
The HTML headers and footers are rendered as independent HTML documents which may have their own assets and stylesheets. It gives developers total control over how their headers and footers look. The height of the rendered headers or footers can be controlled to match their content exactly.
In this example, we show how to add HTML headers and footers to your PDF documents in IronPDF.
HTML headers or footers will be printed onto every page of the PDF when you add them to your project. This can be used to override classic headers and footers.
When using HtmlHeaderFooter, it is important to set HtmlFragment, which will be used to render the headers or footers. It should be an HTML snippet rather than a complete document. It may also contain styles & images.
You can also merge meta-data into your HTML using any of these placeholder strings such as {page} {total-pages} {url} {date} {time} {html-title} {pdf-title}.
Related Docs Links
Ready to get started? Version: 2024.10 just released