Set Custom Margins
from ironpdf import *
 
renderer = ChromePdfRenderer()

# Set Margins (in millimeters)
renderer.RenderingOptions.MarginTop = 40
renderer.RenderingOptions.MarginLeft = 20
renderer.RenderingOptions.MarginRight = 20
renderer.RenderingOptions.MarginBottom = 40

renderer.RenderHtmlFileAsPdf("my-content.html").SaveAs("my-content.pdf")
pip install ironpdf
Set Custom Margins

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.11just released