IRONSOFTWAREHOME
Set Custom Margins
using IronPdf;

var renderer = new 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");
Imports IronPdf

Dim renderer = New 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")
NuGet Download
PM > Install-Package IronPdf
Set Custom Margins

Set Custom Margins

IronPDF allows you to edit margins to any value using RenderingOptions. The HTML to PDF output options for ChromePdfRenderer include specifications such as paper size, DPI, headers and footers, and other Chromium-specific browser setup options. You can also set custom margins with this feature.

This example shows how to set custom margins on your PDF document using IronPDF, a versatile tool for generating and editing PDFs in .NET applications. For more information about IronPDF and its capabilities, visit the IronPDF official website.

The margins can be measured and set in millimeters or inches. For example, the bottom PDF paper margin is in millimeters and can be set to zero to create a document for borderless and commercial printing applications.

However, the default value is 25. For the desired effect, you can customize the top, bottom, left, and right borders individually.

Discover How to Set Custom PDF Margins with IronPDF
View on GitHub

Ready to Get Started?

Nuget Downloads 21,105,021Version: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
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