IRONSOFTWAREHOME

How to Set Paper Margins for Printing in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

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. 1Install IronPrint with NuGet Package Manager

    PM > Install-Package IronPrint

  2. 2Copy 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);
    C#
  3. 3Deploy 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:

using IronPrint;

// Configure a uniform 20 mm margin on all sides
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(20),
    PaperSize = PaperSize.A4
};

// Print the invoice
Printer.Print("invoice.pdf", settings);

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:

using IronPrint;

// Configure per-side margins (left, top, right, bottom)
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(10, 25, 10, 20),
    PaperOrientation = PaperOrientation.Portrait
};

// Print the letterhead
Printer.Print("letterhead.pdf", settings);

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 one additional constructor and one static shorthand field beyond the uniform and per-side versions:

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

using IronPrint;

// Configure horizontal and vertical margin shorthand
PrintSettings settings = new PrintSettings
{
    PaperMargins = new Margins(10, 20)
};

// Print the landscape report
Printer.Print("report-landscape.pdf", settings);

Zero margins - Margins.Zero removes all margins for borderless printing:

using IronPrint;

// Configure zero margins for edge-to-edge printing
PrintSettings borderless = new PrintSettings
{
    PaperMargins = Margins.Zero
};

// Print the poster
Printer.Print("poster.png", borderless);
C#

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:

using IronPrint;

// Configure full print settings with asymmetric margins
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"
};

// Print the Q4 report to the named printer
Printer.Print("Q4-report.pdf", settings);

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.

Frequently Asked Questions

What are print margins in IronPrint?

Print margins in IronPrint control the blank space between document content and the edges of a physical page. They prevent clipped text, maintain consistent layouts, and meet formatting requirements for various documents.

How can I set uniform print margins in C# using IronPrint?

You can set uniform print margins by using the `Margins` class constructor with a single integer value. For example, `new Margins(20)` sets 20 mm margins on all sides.

How do I specify different margins for each side of a document with IronPrint?

To set different margins for each side, use the `Margins` constructor with four parameters: left, top, right, and bottom. For example, `new Margins(10, 25, 10, 20)`.

Can I configure zero print margins with IronPrint?

Yes, IronPrint allows you to configure zero margins using `Margins.Zero`. However, be aware that physical printers may still enforce a minimum printable area.

What is the shorthand method for setting horizontal and vertical margins?

IronPrint offers a shorthand method using `Margins(int horizontal, int vertical)`, where the first value sets the left+right margin and the second value sets the top+bottom margin.

What other print settings can I combine with margins in IronPrint?

In IronPrint, you can combine margins with other settings such as paper size, orientation, DPI, number of copies, and printer selection in a `PrintSettings` object.

How do I install IronPrint in my C# project?

Install IronPrint by using NuGet with the command `Install-Package IronPrint`. Then, add `using IronPrint;` to your project file.

What is the benefit of using millimeters for setting margins in IronPrint?

Using millimeters avoids conversion errors associated with the `System.Drawing.Printing.Margins` class, which uses hundredths of an inch, making it simpler and more intuitive.

How do I print documents asynchronously with IronPrint?

For asynchronous printing, replace `Printer.Print()` with `await Printer.PrintAsync()` in your IronPrint-based workflow to prevent blocking the UI thread.

Where can I find further resources and tutorials for IronPrint?

Further resources for IronPrint can be found on the IronPrint tutorials page, API references for the `Margins` and `Printer` classes, and the Print Settings How-To guide on their website.

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 46,090Version:2026.9just released

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 IronPrint
nuget.org/packages/IronPrint/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPrint"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronPrint to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPrint.dll"

Licenses from $999

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.

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 IronPDF
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