IRONSOFTWAREHOME

MaxHeight vs UseMarginsOnHeaderAndFooter

Curtis Chau
Curtis Chau
Updated: July 21, 2026

When you render a PDF with headers and footers, two properties commonly get conflated: MaxHeight and UseMarginsOnHeaderAndFooter. 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 note: MaxHeight does not add any margin between the header or footer and the main document content. It only caps the section's height.

UseMarginsOnHeaderAndFooter

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>");
C#

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

The UseMarginsOnHeaderAndFooter 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 AddHtmlHeaders() and AddHtmlFooters() methods 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 21,105,021Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999