Skip to content
English
  • There are no suggestions because the search field is empty.

[Public] Understanding MaxHeight in Header and Footer object

This article will explain the difference between these 2 features to assist in rendering PDF with Header and Footer

 

MaxHeight vs UseMarginToHeaderAndFooter

When working with PDF generation, especially with implementation of Headers and Footers, layout and margin control is essential for producing clean and readable documents. Two properties often used to manage spacing between Header and Footer content with structural elements are:

 

1. MaxHeight: Control allowable height for Header/Footer section

The MaxHeight property defines the maximum height allocated for the header or footer section in a rendered PDF. By default, IronPDF dynamically adjusts this height to ensure that all header or footer content is displayed.

However, if you manually reduce MaxHeight, any content that exceeds the specified height will be clipped or hidden. On the other hand, assigning an overly large value will not increase the visible size of the header or footer. Instead, IronPDF will revert to its default sizing to maintain layout stability.

Note: This property does not affect or add additional margins between the header/footer and the main document content.

Example Use:

Screenshot 2025-06-12 120048

 

Consider the following use cases on rendering a simple PDF with header and footer with varying MaxHeight value:

  • MaxHeight = 10
    Screenshot 2025-06-12 140449

  • MaxHeight = 15
    Screenshot 2025-06-12 140510

  • MaxHeight = 50
    Screenshot 2025-06-12 140601 

  • MaxHeight = 100
    Screenshot 2025-06-12 140537
  

2. UseMarginToHeaderAndFooter: Extend Body Margins to Headers and Footers

Unlike content margins set via ChromePdfRenderOptions, headers and footers have their own layout handling. For precise control over spacing, it is best to define margins directly within the HTML content of the Header or Footer object.

 

var renderer = new ChromePdfRenderer();

renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = @"<div style=""margin-top: 20 px; margin-right: 40px; margin-bottom: 10px; margin-left: 30px; background-color: lightblue;"">
   This is Header
  </div>",
  DrawDividerLine = true,
  MaxHeight = 30
};

var pdf = renderer.RenderHtmlAsPdf(" < h1 > Hello World </ h1 > ");

 
UseMarginToHeaderAndFooter Property

The UseMarginToHeaderAndFooter property allows the margins defined for the main content (e.g., left and right margins) to also apply to the header and footer sections. However, this should be used with caution. In many cases, it may lead to unexpected layout results—such as overlapping content—especially when vertical margins (top/bottom) are applied.

 

Recommended: Use only for left and right margin alignment when necessary, or use this property with AddHtmlHeaderFooter() method if UseMargins.All is required.

⚠️ Avoid using for top and bottom margins unless the layout has been tested.

Screenshot 2025-06-12 142247

 

By understanding and correctly applying MaxHeight and UseMarginToHeaderAndFooter, you can gain fine control over the appearance and spacing of header and footer sections in your PDF documents—leading to cleaner layouts and better presentation.