MaxHeight vs UseMarginToHeaderAndFooter

When you render a PDF with headers and footers, two properties commonly get conflated: MaxHeight and UseMarginToHeaderAndFooter. They control different things, and mixing them up leads to clipped content or unexpected overlaps. Here is what each one does and when to reach for it.

MaxHeight

MaxHeight sets the maximum height allocated to the header or footer section in the rendered PDF. By default, IronPDF adjusts this height dynamically so all header or footer content fits.

Manually lowering MaxHeight clips or hides any content that exceeds the value you set. Going the other way, an oversized value does not enlarge the visible header or footer; IronPDF falls back to its default sizing to keep the layout stable.

Rendered PDF with MaxHeight 10 where the header text is clipped

Rendered PDF with MaxHeight 15 where the header text is partially clipped

Rendered PDF with MaxHeight 50 showing the full header

Rendered PDF with MaxHeight 100 showing identical sizing to the default

Please noteMaxHeight does not add any margin between the header or footer and the main document content. It only caps the section's height.

UseMarginToHeaderAndFooter

Headers and footers have their own layout handling, separate from the content margins set through ChromePdfRenderOptions. For precise spacing, define margins directly in the HTML of the Header or Footer object:

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = @"<div style=""margin-top: 20px; 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>");
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = @"<div style=""margin-top: 20px; 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>");
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
    .HtmlFragment = "<div style=""margin-top: 20px; margin-right: 40px; margin-bottom: 10px; margin-left: 30px; background-color: lightblue;"">
   This is Header
  </div>",
    .DrawDividerLine = True,
    .MaxHeight = 30
}
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
$vbLabelText   $csharpLabel

Styling the header inside its own HtmlFragment keeps spacing predictable, since the margins live with the content they apply to.

The UseMarginToHeaderAndFooter property extends the main content margins (such as left and right) to the header and footer sections. Use it carefully: applying vertical margins (top and bottom) this way often produces overlapping content and other surprises.

  • Recommended: Apply it only for left and right margin alignment when you need it, or pair it with the AddHtmlHeaderFooter() method when UseMargins.All is required.
  • Avoid: Using it for top and bottom margins unless you have tested the resulting layout.
Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 19,680,294 | Version: 2026.7 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronPdf
run a sample watch your HTML become a PDF.