Table of Contents

Class PdfMargins

Namespace
Syncfusion.Pdf.Graphics
Assembly
Syncfusion.Pdf.Portable.dll

A class representing PDF page margins.

public class PdfMargins : ICloneable
Inheritance
PdfMargins
Implements
Inherited Members

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set all the side of the page margin.
margin.All = 20;       
//Set margin
document.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = document.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set all the side of page margin.
margin.All = 20        
'Set margin.
document.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = document.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)

Constructors

PdfMargins()

Initializes a new instance of the PdfMargins class.

public PdfMargins()

Properties

All

Sets margin of each side of the page

public float All { set; }

Property Value

float

Margin of each side.

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set all the side of the page margin.
margin.All = 20;       
//Set margin
document.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = document.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set all the side of page margin.
margin.All = 20        
'Set margin.
document.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = document.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)

Remarks

Default value: 40 pixels

Bottom

Gets or sets the bottom margin size.

public float Bottom { get; set; }

Property Value

float

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set left margin.
margin.Left = 20;
//Set right margin.
margin.Right = 40;
//Set top margin.
margin.Top = 100;
//Set bottom margin.
margin.Bottom = 100;
//Set margin.
document.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = document.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set left margin.
margin.Left = 20
'Set right margin.
margin.Right = 40
'Set top margin.
margin.Top = 100
'Set bottom margin.
margin.Bottom = 100
'Set margin.
document.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = document.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)

Remarks

Default value: 40 pixels

Left

Gets or sets the left margin size.

public float Left { get; set; }

Property Value

float

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set left margin.
margin.Left = 20;
//Set right margin.
margin.Right = 40;
//Set top margin.
margin.Top = 100;
//Set bottom margin.
margin.Bottom = 100;
//Set margin.
document.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = document.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set left margin.
margin.Left = 20
'Set right margin.
margin.Right = 40
'Set top margin.
margin.Top = 100
'Set bottom margin.
margin.Bottom = 100
'Set margin.
document.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = document.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)

Remarks

Default value: 40 pixels

Right

Gets or sets the right margin size.

public float Right { get; set; }

Property Value

float

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set left margin.
margin.Left = 20;
//Set right margin.
margin.Right = 40;
//Set top margin.
margin.Top = 100;
//Set bottom margin.
margin.Bottom = 100;
//Set margin.
document.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = document.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set left margin.
margin.Left = 20
'Set right margin.
margin.Right = 40
'Set top margin.
margin.Top = 100
'Set bottom margin.
margin.Bottom = 100
'Set margin.
document.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = document.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)

Remarks

Default value: 40 pixels

Top

Gets or sets the top margin size.

public float Top { get; set; }

Property Value

float

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set left margin.
margin.Left = 20;
//Set right margin.
margin.Right = 40;
//Set top margin.
margin.Top = 100;
//Set bottom margin.
margin.Bottom = 100;
//Set margin.
document.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = document.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set left margin.
margin.Left = 20
'Set right margin.
margin.Right = 40
'Set top margin.
margin.Top = 100
'Set bottom margin.
margin.Bottom = 100
'Set margin.
document.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = document.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)

Remarks

Default value: 40 pixels

Methods

Clone()

Clones the object.

public object Clone()

Returns

object

The cloned object.

Examples

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Create new PDF margin.
PdfMargins margin = new PdfMargins();
//Set left margin.
margin.All = 20;
//Create new PDF section.
PdfSection section = document.Sections.Add();
//Set margin.
section.PageSettings.Margins = margin;
//Adds a page.PdfPage 
PdfPage page = section.Pages.Add();
//Creates PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Create new PDF section.
section = document.Sections.Add();
//Clone the margin.
PdfMargins margin1 = margin.Clone() as PdfMargins;
margin1.Left = 30;
//set marign.
section.PageSettings.Margins = margin1;
page = section.Pages.Add();
//Creates PDF graphics for the page.
graphics = page.Graphics;
//Draws the String.
graphics.DrawRectangle(PdfPens.Red, new RectangleF(new PointF(0, 0), page.GetClientSize()));
//Saves the document.
document.Save("output.pdf");
//Closes the document.
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Create new PDF margin.
Dim margin As New PdfMargins()
'Set left margin.
margin.All = 20
'Create new PDF section.
Dim section As PdfSection = document.Sections.Add()
'Set margin.
section.PageSettings.Margins = margin
'Adds a page.PdfPage 
Dim page As PdfPage = section.Pages.Add()
'Creates PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Create new PDF section.
section = document.Sections.Add()
'Clone the margin.
Dim margin1 As PdfMargins = TryCast(margin.Clone(), PdfMargins)
margin1.Left = 30
'set marign.
section.PageSettings.Margins = margin1
page = section.Pages.Add()
'Creates PDF graphics for the page.
graphics = page.Graphics
'Draws the String.
graphics.DrawRectangle(PdfPens.Red, New RectangleF(New PointF(0, 0), page.GetClientSize()))
'Saves the document.
document.Save("output.pdf")
'Closes the document.
document.Close(True)