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 Case | Suggested Margin |
|---|---|
| Standard document | 20 mm all sides |
| With header/footer | 40 mm top/bottom, 20 mm left/right |
| Narrow binding | 30 mm left, 15 mm right |
| Wide print | 10 mm all sides |
Margins are set in millimeters. To use inches, multiply by 25.4.






