Add Headers/Footers on Specific Pages

Adding headers and footers to freshly rendered PDFs or existing PDF documents is straightforward with IronPDF.

You can use the addHtmlHeader method to add a header and the addHtmlFooter method to add a footer. These methods require an object that contains the following properties: dividerLine, dividerLineColor, htmlFragment, loadStylesAndCSSFromMainHtmlDocument, and maxHeight.

  • dividerLine: Applies a divider line after the header or footer.
  • dividerLineColor: Customizes the divider color.
  • htmlFragment: Specifies the HTML string to be used for the header or footer.
  • loadStylesAndCSSFromMainHtmlDocument: Enables loading CSS from the main HTML document. This feature only works when rendering from HTML to PDF.
  • maxHeight: Sets a maximum height for the header and footer.

Afterward, you can specify the second parameter, which is the page number to which the header or footer will be applied. The specification can be for a single page, multiple pages, or all pages using the string "all." If the page number has not been specified, the method will apply the header or footer to all pages.