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
- Install IronPrint via NuGet:
Install-Package IronPrint - Add
using IronPrint;to the file - Create a
PrintSettingsobject - Assign a
Marginsvalue toPaperMargins(values in millimeters) - Pass settings to
Printer.Print()with the file path
-
Install IronPrint with NuGet Package Manager
PM > Install-Package IronPrint -
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); -
Deploy to test on your live environment
Start using IronPrint in your project today with a free trial
Minimal Workflow (5 steps)
- Install the IronPrint C# printing library
- Create a
PrintSettingsobject - Assign a
Marginsvalue toPaperMargins - Pass settings to
Printer.Print() - Run the project to print with custom margins
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/set-paper-margins-uniform-margins.cs
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);
Imports IronPrint
' Configure a uniform 20 mm margin on all sides
Dim settings As New PrintSettings With {
.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:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-per-side-margins.cs
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);
Imports IronPrint
' Configure per-side margins (left, top, right, bottom)
Dim settings As New PrintSettings With {
.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 two additional constructors 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:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-shorthand-margins.cs
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);
Imports IronPrint
' Configure horizontal and vertical margin shorthand
Dim settings As New PrintSettings With {
.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:
:path=/static-assets/print/content-code-examples/how-to/set-paper-margins/set-paper-margins-zero-margins.cs
using IronPrint;
// Configure zero margins for edge-to-edge printing
PrintSettings borderless = new PrintSettings
{
PaperMargins = new Margins(0)
};
// Print the poster
Printer.Print("poster.png", borderless);
Imports IronPrint
' Configure zero margins for edge-to-edge printing
Dim borderless As New PrintSettings With {
.PaperMargins = New Margins(0)
}
' Print the poster
Printer.Print("poster.png", borderless)
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/set-paper-margins-combined-settings.cs
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);
Imports IronPrint
' Configure full print settings with asymmetric margins
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"
}
' 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:
- IronPrint Tutorials — Print Document for end-to-end printing walkthroughs.
- Print Settings How-To for DPI, orientation, copies, and more.
Marginsclass API reference for complete constructor and field documentation.PrinterClass API Reference for all static printing methods.
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 is IronPrint and how does it help with setting print margins in C#?
IronPrint is a .NET library that simplifies setting print margins in C#. It offers a Margins class that allows developers to easily customize print margins with uniform, per-side, and borderless options using just one line of code.
How can I set uniform margins for printing in C# using IronPrint?
To set uniform margins for printing in C# with IronPrint, you can use the Margins class. This class enables you to specify the same margin size for all sides of the page in a single line of code.
Is it possible to set different margins for each side of the page in C#?
Yes, IronPrint allows you to set different margins for each side of the page in C#. The Margins class provides options to customize the top, bottom, left, and right margins individually.
Can I create borderless prints using IronPrint?
IronPrint supports the creation of borderless prints. By adjusting the margins using the Margins class, you can set the margins to zero, effectively producing a borderless print.
What are the benefits of using IronPrint for setting paper margins?
IronPrint streamlines the process of setting paper margins in C# by providing a straightforward and efficient API. Its Margins class simplifies code and enhances productivity, making it easier to implement custom printing requirements.
Do I need extensive coding knowledge to set print margins with IronPrint?
No, you do not need extensive coding knowledge to set print margins with IronPrint. The library is designed to be user-friendly, allowing even those with basic C# skills to implement custom margins easily.
How does IronPrint handle different paper sizes when setting margins?
IronPrint adapts to various paper sizes by allowing you to specify margins that suit the specific dimensions of your document. This flexibility ensures that your print outputs meet your specific layout needs.
Can IronPrint be integrated with other .NET applications?
Yes, IronPrint can be seamlessly integrated with other .NET applications, allowing you to incorporate custom print margin settings into a wide range of projects and workflows.

