Add Classic Text Headers & Footers
There are two methods through which headers and footers may be added to a PDF document. They can either be added as a classic text format, with the option to merge in dynamic data. Or, they can be added through the much more flexible HTML format, which allows developers to render dynamic headers and footers through their HTML content.
Steps to Add Headers and Footers to PDFs with IronPDF
// Ensure you have included the IronPdf library in your project
using IronPdf;
// Instantiate a ChromePdfRenderer for rendering PDFs
var renderer = new ChromePdfRenderer();
// Configure header options
// Enable a divider line for the header
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
// Center the text in the header, using the document URL as content
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
// Select a font type and size for the header text
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
// Additional header configurations can be made such as setting a margin
// Ensure you have included the IronPdf library in your project
using IronPdf;
// Instantiate a ChromePdfRenderer for rendering PDFs
var renderer = new ChromePdfRenderer();
// Configure header options
// Enable a divider line for the header
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
// Center the text in the header, using the document URL as content
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
// Select a font type and size for the header text
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
// Additional header configurations can be made such as setting a margin
' Ensure you have included the IronPdf library in your project
Imports IronPdf
' Instantiate a ChromePdfRenderer for rendering PDFs
Private renderer = New ChromePdfRenderer()
' Configure header options
' Enable a divider line for the header
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
' Center the text in the header, using the document URL as content
renderer.RenderingOptions.TextHeader.CenterText = "{url}"
' Select a font type and size for the header text
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
' Additional header configurations can be made such as setting a margin
Today we will be looking at how you can add classic text headers and footers into your PDF documents in just a few simple steps. The first step towards adding customized Headers and Footers into your PDF documents is to ensure that the IronPDF library is included in your project with the using IronPdf;
statement. Then, instantiate the ChromePdfRenderer
, which provides the functionality to render your HTML content in pixel-perfect PDF documents.
Next, configure the header settings. The FirstPageNumber
property allows you to specify the starting page number, accommodating for a cover page if needed. The TextHeader
properties enable you to customize the appearance, such as drawing a divider line, centering text (in this case, the document URL), selecting the font type and size, and creating a margin at the top of the page for the header.
After configuring the header, set up the footer using the TextFooter
properties. Similar to the header, you can draw a divider line, choose the font type and size, and include dynamic content like the current date, time, and page numbers with total pages. Finally, a margin is created at the bottom of the page to accommodate the footer.
By following these steps, you can enhance your PDF documents with informative headers and footers that improve their professionalism and readability.
Click here to view the How-to Guide, including examples, sample code, and files