Set Custom Margins

IronPDF for Python lets you set precise page margins on generated PDFs using the MarginTop, MarginLeft, MarginRight, and MarginBottom properties of RenderingOptions.

Getting Started

Create a ChromePdfRenderer, set each margin property to the desired value in millimeters, and then call a render method. The margins are applied to every page in the resulting PDF.

Understanding the Code

  • MarginTop: Space in millimeters between the top edge of the page and the content area. Also used to reserve space for HTML headers.
  • MarginLeft: Space between the left edge of the page and the content area.
  • MarginRight: Space between the right edge of the page and the content area.
  • MarginBottom: Space between the bottom edge of the page and the content area. Also used to reserve space for HTML footers.
  • RenderHtmlFileAsPdf("my-content.html"): Renders the local HTML file with the configured margins applied.

Common Margin Values

Use CaseSuggested Margin
Standard document20 mm all sides
With header/footer40 mm top/bottom, 20 mm left/right
Narrow binding30 mm left, 15 mm right
Wide print10 mm all sides

Margins are set in millimeters. To use inches, multiply by 25.4.

Ready to Get Started?
Version: 2026.6 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast?
run a sample watch your HTML become a PDF.