How to Set Paper Margins for Printing in C#

Print margins control the blank space between your document content and the edges of the physical page. Getting them right prevents clipped text, ensures consistent layouts across printers, and satisfies formatting requirements for invoices, reports, and legal documents.

IronPrint's Margins class accepts values in millimeters and offers three constructor overloads — uniform, horizontal/vertical, and per-side — so we can match any layout requirement in a single line. We walk through each approach below, from installation to printing with custom margins.

Quickstart: Set Paper Margins

  1. Install IronPrint via NuGet: Install-Package IronPrint
  2. Add using IronPrint; to the file
  3. Create a PrintSettings object
  4. Assign a Margins value to PaperMargins (values in millimeters)
  5. Pass settings to Printer.Print() with the file path
  1. Install IronPrint with NuGet Package Manager

    PM > Install-Package IronPrint
  2. Copy and run this code snippet.

    using IronPrint;
    
    // Set 15 mm margins on all sides and print
    PrintSettings settings = new PrintSettings();
    settings.PaperMargins = new Margins(15);
    Printer.Print("report.pdf", settings);
  3. Deploy to test on your live environment

    Start using IronPrint in your project today with a free trial

    arrow pointer

How Can I Set Equal Margins on All Sides?

The simplest constructor takes a single integer and applies it uniformly to all four sides. We pass the value in millimeters:

:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/uniform-margins.cs
using IronPrint;

// 20 mm margin on every side
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(20),
    PaperSize = PaperSize.A4
};

Printer.Print("invoice.pdf", settings);
Imports IronPrint

' 20 mm margin on every side
Dim settings As New PrintSettings With {
    .PaperMargins = New Margins(20),
    .PaperSize = PaperSize.A4
}

Printer.Print("invoice.pdf", settings)
$vbLabelText   $csharpLabel

Margins(20) sets Left, Top, Right, and Bottom each to 20 mm. This is the most common choice for standard business documents where consistent whitespace on every edge is sufficient.

IronPrint measures margins in millimeters, which avoids the confusion of the System.Drawing.Printing.Margins class that uses hundredths of an inch. A 25.4 mm margin in IronPrint is equivalent to new System.Drawing.Printing.Margins(100) — no conversion math required on our end.

How Do I Set Different Margins for Each Side?

When a document needs extra space at the top for a letterhead or at the bottom for a footer, we use the four-parameter constructor:

:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/per-side-margins.cs
using IronPrint;

// Left: 10 mm, Top: 25 mm, Right: 10 mm, Bottom: 20 mm
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(10, 25, 10, 20),
    PaperOrientation = PaperOrientation.Portrait
};

Printer.Print("letterhead.pdf", settings);
Imports IronPrint

' Left: 10 mm, Top: 25 mm, Right: 10 mm, Bottom: 20 mm
Dim settings As New PrintSettings With {
    .PaperMargins = New Margins(10, 25, 10, 20),
    .PaperOrientation = PaperOrientation.Portrait
}

Printer.Print("letterhead.pdf", settings)
$vbLabelText   $csharpLabel

The parameter order is left, top, right, bottom. Each value is independent, so we can create asymmetric layouts that accommodate headers, footers, binding edges, or punch-hole space. The Margins class API reference documents every field.

What Shorthand Options Exist for Common Margin Layouts?

IronPrint's Margins class provides two additional constructors beyond the uniform and per-side versions:

Horizontal / Vertical shorthandMargins(int horizontal, int vertical) sets left+right to the first value and top+bottom to the second:

:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/shorthand-margins.cs
using IronPrint;

// 10 mm left & right, 20 mm top & bottom
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(10, 20)
};

Printer.Print("report-landscape.pdf", settings);
Imports IronPrint

' 10 mm left & right, 20 mm top & bottom
Dim settings As New PrintSettings With {
    .PaperMargins = New Margins(10, 20)
}

Printer.Print("report-landscape.pdf", settings)
$vbLabelText   $csharpLabel

Zero marginsMargins.Zero removes all margins for borderless printing:

:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/zero-margins.cs
PrintSettings borderless = new PrintSettings
{
    PaperMargins = Margins.Zero
};

Printer.Print("poster.png", borderless);
Dim borderless As New PrintSettings With {
    .PaperMargins = Margins.Zero
}

Printer.Print("poster.png", borderless)
$vbLabelText   $csharpLabel

Keep in mind that most physical printers enforce a hardware-minimum printable area. Setting Margins.Zero sends zero-margin instructions to the driver, but the printer may still clip content near the edges depending on its capabilities.

How Do I Combine Margins with Other Print Settings?

PaperMargins is one property on PrintSettings. We can combine it with paper size, orientation, DPI, copies, grayscale mode, and printer selection in a single configuration object:

:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/combined-settings.cs
using IronPrint;

// Full print configuration for a quarterly report
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(15, 20, 15, 25),
    PaperSize = PaperSize.A4,
    PaperOrientation = PaperOrientation.Portrait,
    Dpi = 300,
    NumberOfCopies = 2,
    Grayscale = false,
    PrinterName = "HP LaserJet Pro MFP M428"
};

Printer.Print("Q4-report.pdf", settings);
Imports IronPrint

' Full print configuration for a quarterly report
Dim settings As New PrintSettings With {
    .PaperMargins = New Margins(15, 20, 15, 25),
    .PaperSize = PaperSize.A4,
    .PaperOrientation = PaperOrientation.Portrait,
    .Dpi = 300,
    .NumberOfCopies = 2,
    .Grayscale = False,
    .PrinterName = "HP LaserJet Pro MFP M428"
}

Printer.Print("Q4-report.pdf", settings)
$vbLabelText   $csharpLabel

For asynchronous workflows — WPF, MAUI, or ASP.NET web apps — replace Printer.Print() with await Printer.PrintAsync() to avoid blocking the UI thread. The same PrintSettings object works with both methods.

What Are My Next Steps?

We covered four ways to configure print margins with IronPrint: uniform margins using Margins(int), per-side control with Margins(int, int, int, int), the horizontal/vertical shorthand Margins(int, int), and borderless printing with Margins.Zero. Each approach feeds into PrintSettings.PaperMargins and works with both Printer.Print() and Printer.PrintAsync().

For further reading, explore these resources:

Get a free trial license to test every feature in a live environment, or view licensing options when you're ready to deploy.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 37,845 | Version: 2026.3 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronPrint
run a sample watch your document hit the printer.