PdfMargins Class
A class representing PDF page margins.
Inheritance
System.Object
PdfMargins
Implements
System.ICloneable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfMargins : ICloneable
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.
Declaration
public PdfMargins()
Properties
All
Sets margin of each side of the page
Declaration
public float All { set; }
Property Value
Type | Description |
---|---|
System.Single | Margin of each side. |
Remarks
Default value: 40 pixels
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)
Bottom
Gets or sets the bottom margin size.
Declaration
public float Bottom { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value: 40 pixels
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)
Left
Gets or sets the left margin size.
Declaration
public float Left { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value: 40 pixels
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)
Right
Gets or sets the right margin size.
Declaration
public float Right { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value: 40 pixels
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)
Top
Gets or sets the top margin size.
Declaration
public float Top { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value: 40 pixels
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)
Methods
Clone()
Clones the object.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.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)
Implements
System.ICloneable