Table of Contents

Class PdfPolygon

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

Represents a set of points connected with lines, could be drawn and filled.

public class PdfPolygon : PdfFillElement
Inheritance
PdfPolygon
Inherited Members

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(50, 50);
PointF point2 = new PointF(100, 50);
PointF point3 = new PointF(150, 100);
PointF point4 = new PointF(150, 150);
PointF point5 = new PointF(100, 200);
PointF point6 = new PointF(50, 200);
PointF point7 = new PointF(0, 150);
PointF point8 = new PointF(0, 100);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(points);
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(50, 50)
Dim point2 As New PointF(100, 50)
Dim point3 As New PointF(150, 100)
Dim point4 As New PointF(150, 150)
Dim point5 As New PointF(100, 200)
Dim point6 As New PointF(50, 200)
Dim point7 As New PointF(0, 150)
Dim point8 As New PointF(0, 100)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(points)
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

Constructors

PdfPolygon()

Initializes a new instance of the PdfPolygon class.

protected PdfPolygon()

PdfPolygon(PointF[])

Initializes a new instance of the PdfPolygon class.

public PdfPolygon(PointF[] points)

Parameters

points PointF[]

The points that represents the vertices of the polygon.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(50, 50);
PointF point2 = new PointF(100, 50);
PointF point3 = new PointF(150, 100);
PointF point4 = new PointF(150, 150);
PointF point5 = new PointF(100, 200);
PointF point6 = new PointF(50, 200);
PointF point7 = new PointF(0, 150);
PointF point8 = new PointF(0, 100);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(points);
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(50, 50)
Dim point2 As New PointF(100, 50)
Dim point3 As New PointF(150, 100)
Dim point4 As New PointF(150, 150)
Dim point5 As New PointF(100, 200)
Dim point6 As New PointF(50, 200)
Dim point7 As New PointF(0, 150)
Dim point8 As New PointF(0, 100)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(points)
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

PdfPolygon(PdfBrush, PointF[])

Initializes a new instance of the PdfPolygon class.

public PdfPolygon(PdfBrush brush, PointF[] points)

Parameters

brush PdfBrush

The brush of the polygon shape.

points PointF[]

The points that represents the vertices of the polygon.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(100, 100);
PointF point2 = new PointF(150, 100);
PointF point3 = new PointF(200, 150);
PointF point4 = new PointF(200, 200);
PointF point5 = new PointF(150, 250);
PointF point6 = new PointF(100, 250);
PointF point7 = new PointF(50, 200);
PointF point8 = new PointF(50, 150);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(PdfBrushes.Red, points);
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(100, 100)
Dim point2 As New PointF(150, 100)
Dim point3 As New PointF(200, 150)
Dim point4 As New PointF(200, 200)
Dim point5 As New PointF(150, 250)
Dim point6 As New PointF(100, 250)
Dim point7 As New PointF(50, 200)
Dim point8 As New PointF(50, 150)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(PdfBrushes.Red, points)
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

PdfPolygon(PdfPen, PointF[])

Initializes a new instance of the PdfPolygon class.

public PdfPolygon(PdfPen pen, PointF[] points)

Parameters

pen PdfPen

The pen of the polygon shape.

points PointF[]

The points that represents the vertices of the polygon.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(100, 100);
PointF point2 = new PointF(150, 100);
PointF point3 = new PointF(200, 150);
PointF point4 = new PointF(200, 200);
PointF point5 = new PointF(150, 250);
PointF point6 = new PointF(100, 250);
PointF point7 = new PointF(50, 200);
PointF point8 = new PointF(50, 150);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(PdfPens.Red, points);
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(100, 100)
Dim point2 As New PointF(150, 100)
Dim point3 As New PointF(200, 150)
Dim point4 As New PointF(200, 200)
Dim point5 As New PointF(150, 250)
Dim point6 As New PointF(100, 250)
Dim point7 As New PointF(50, 200)
Dim point8 As New PointF(50, 150)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(PdfPens.Red, points)
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

PdfPolygon(PdfPen, PdfBrush, PointF[])

Initializes a new instance of the PdfPolygon class.

public PdfPolygon(PdfPen pen, PdfBrush brush, PointF[] points)

Parameters

pen PdfPen

The pen of the polygon shape.

brush PdfBrush

The brush of the polygon shape.

points PointF[]

The points that represents the vertices of the polygon.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(100, 100);
PointF point2 = new PointF(150, 100);
PointF point3 = new PointF(200, 150);
PointF point4 = new PointF(200, 200);
PointF point5 = new PointF(150, 250);
PointF point6 = new PointF(100, 250);
PointF point7 = new PointF(50, 200);
PointF point8 = new PointF(50, 150);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(PdfPens.Black, PdfBrushes.Red, points);
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(100, 100)
Dim point2 As New PointF(150, 100)
Dim point3 As New PointF(200, 150)
Dim point4 As New PointF(200, 200)
Dim point5 As New PointF(150, 250)
Dim point6 As New PointF(100, 250)
Dim point7 As New PointF(50, 200)
Dim point8 As New PointF(50, 150)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(PdfPens.Black, PdfBrushes.Red, points)
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

Properties

Count

Gets a number of the points in the polygon.

public int Count { get; }

Property Value

int

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(100, 100);
PointF point2 = new PointF(150, 100);
PointF point3 = new PointF(200, 150);
PointF point4 = new PointF(200, 200);
PointF point5 = new PointF(150, 250);
PointF point6 = new PointF(100, 250);
PointF point7 = new PointF(50, 200);
PointF point8 = new PointF(50, 150);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(PdfPens.Red, points);
//Get the polygon points count.
int count = polygon.Count;
Console.WriteLine("Polygon points count: " + count);
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(100, 100)
Dim point2 As New PointF(150, 100)
Dim point3 As New PointF(200, 150)
Dim point4 As New PointF(200, 200)
Dim point5 As New PointF(150, 250)
Dim point6 As New PointF(100, 250)
Dim point7 As New PointF(50, 200)
Dim point8 As New PointF(50, 150)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(PdfPens.Red, points)
'Get the polygon points count.
Dim count As Integer = polygon.Count
Console.WriteLine("Polygon points count: " + count)
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

Points

Gets or sets the points of the polygon.

public PointF[] Points { get; set; }

Property Value

PointF[]

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(100, 100);
PointF point2 = new PointF(150, 100);
PointF point3 = new PointF(200, 150);
PointF point4 = new PointF(200, 200);
PointF point5 = new PointF(150, 250);
PointF point6 = new PointF(100, 250);
PointF point7 = new PointF(50, 200);
PointF point8 = new PointF(50, 150);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(PdfPens.Black, new PointF[] { new PointF(0,100) });
//Set the polygon points.        
polygon.Points = points;
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(100, 100)
Dim point2 As New PointF(150, 100)
Dim point3 As New PointF(200, 150)
Dim point4 As New PointF(200, 200)
Dim point5 As New PointF(150, 250)
Dim point6 As New PointF(100, 250)
Dim point7 As New PointF(50, 200)
Dim point8 As New PointF(50, 150)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(PdfPens.Black, New PointF() {New PointF(0, 100)})
'Set the polygon points.
polygon.Points = points
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

Methods

AddPoint(PointF)

Adds a point to the polygon.

public void AddPoint(PointF point)

Parameters

point PointF

The last point of the polygon.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Polygon points.            
PointF point1 = new PointF(100, 100);
PointF point2 = new PointF(150, 100);
PointF point3 = new PointF(200, 150);
PointF point4 = new PointF(200, 200);
PointF point5 = new PointF(150, 250);
PointF point6 = new PointF(100, 250);
PointF point7 = new PointF(50, 200);
PointF point8 = new PointF(50, 150);
PointF[] points = { point1, point2, point3, point4, point5, point6, point7, point8 };
//Create a new PDF polygon instance.            
PdfPolygon polygon = new PdfPolygon(PdfPens.Red, points);
//Add points.
polygon.AddPoint(new PointF(50, 50));
//Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Polygon points.            
Dim point1 As New PointF(100, 100)
Dim point2 As New PointF(150, 100)
Dim point3 As New PointF(200, 150)
Dim point4 As New PointF(200, 200)
Dim point5 As New PointF(150, 250)
Dim point6 As New PointF(100, 250)
Dim point7 As New PointF(50, 200)
Dim point8 As New PointF(50, 150)
Dim points As PointF() = {point1, point2, point3, point4, point5, point6, point7, point8}
'Create a new PDF polygon instance.
Dim polygon As New PdfPolygon(PdfPens.Red, points)
'Add points.
polygon.AddPoint(New PointF(50, 50))
'Draw the polygon to PDF page.
polygon.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)

DrawInternal(PdfGraphics)

Draws an element on the Graphics.

protected override void DrawInternal(PdfGraphics graphics)

Parameters

graphics PdfGraphics

Graphics context where the element should be printed.

GetBoundsInternal()

Overloaded. Returns a rectangle that bounds this element.

protected override RectangleF GetBoundsInternal()

Returns

RectangleF

Returns a rectangle that bounds this element.