Add HTML Headers & Footers
const {PdfDocument} = require("@ironsoftware/ironpdf");

(async () => {
    // Configure render options
    const renderOptions = {
        firstPageNumber: 1, // Use 2 if a cover page will be appended

        // Build a footer using html to style the text
        // mergeable fields are:
        // {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
        htmlFooter: {
            maxHeight: 15, //millimeters
            htmlFragment: "<center><i>{page} of {total-pages}<i></center>",
            dividerLine: true,
        },

        // Build a header using an image asset
        htmlHeader: {
            maxHeight: 15, //millimeters
            htmlFragment: "<img src='logo.png'>",
        },

        // Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
        margin: {
            top: 25, // Create 25mm space for the header
            bottom: 25, // Create 25mm space for the footer
        },
    };
})();
npm i @ironsoftware/ironpdf
Add HTML Headers & Footers

Add HTML Headers & Footers

Configure the rendering options to include an HTML header and footer when rendering a PDF document with IronPDF, a library by Iron Software that allows for advanced PDF generation and manipulation.

Define the header content with a divider line, an HTML fragment, and specify the maximum height of the header using IronPdf's flexible PDF rendering tools. Similarly, define the footer content using the htmlHeader property provided by IronPDF.

Note that the height of the header and footer is not automatically detected, which means they might overlap with the main HTML content. Customize the margins to ensure the header and footer are appropriately positioned.

Explore HTML Headers & Footers Code Example on GitHub
View on GitHub

Ready to Get Started?

Version:2026.11just released