IRONSOFTWAREHOME
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.9just released

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
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999