How to Add a Polygon Annotation to PDF in C#, VB.NET

Polygon annotations are displayed as a series of connected vertices and can be double-clicked to display its note. Users can customize the shape of polygon by setting the vertex coordinates. This article will introduce how to add a polygon annotation to PDF using Spire.PDF.

Step 1: Create a PDF document object, add a new page.

PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();

Step 2: Initialize an instance of PdfPolygonAnnotation, specifying all vertex coordinates which can form a complete shape.

PdfPolygonAnnotation polygon = new PdfPolygonAnnotation(page, new PointF[] { new PointF(0, 30), new PointF(30, 15), new PointF(60, 30),
new PointF(45, 50), new PointF(15, 50), new PointF(0, 30)});

Step 3: Set the border color, text, border effect and other properties of polygon annotation.

polygon.Color = Color.PaleVioletRed;
polygon.Text = "This is a polygon annotation";
polygon.Author = "E-ICEBLUE";
polygon.Subject = "polygon annotation demo";
polygon.BorderEffect = PdfBorderEffect.BigCloud;
polygon.ModifiedDate = DateTime.Now;

Step 4: Add the annotation to PDF page and save the document.

page.AnnotationsWidget.Add(polygon);
pdf.SaveToFile("Polygon_Annotation.pdf");

Result:

How to Add a Polygon Annotation to PDF in C#, VB.NET

Full Code:

[C#]
PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();

PdfPolygonAnnotation polygon = new PdfPolygonAnnotation(page, new PointF[] { new PointF(0, 30), new PointF(30, 15), new PointF(60, 30),
    new PointF(45, 50), new PointF(15, 50), new PointF(0, 30)});
polygon.Color = Color.PaleVioletRed;
polygon.Text = "This is a polygon annotation";
polygon.Author = "E-ICEBLUE";
polygon.Subject = "polygon annotation demo";
polygon.BorderEffect = PdfBorderEffect.BigCloud;
polygon.ModifiedDate = DateTime.Now;

page.AnnotationsWidget.Add(polygon);
pdf.SaveToFile("Polygon_Annotation.pdf");
[VB.NET]
Dim pdf As PdfDocument = New PdfDocument()
Dim page As PdfPageBase = pdf.Pages.Add()

PdfPolygonAnnotation polygon = New PdfPolygonAnnotation(page, New PointF()
{
    New PointF(0, 30), New PointF(30, 15), New PointF(60, 30),
    New PointF(45, 50), New PointF(15, 50), New PointF(0, 30)
    }
)
polygon.Color = Color.PaleVioletRed
polygon.Text = "This is a polygon annotation"
polygon.Author = "E-ICEBLUE"
polygon.Subject = "polygon annotation demo"
polygon.BorderEffect = PdfBorderEffect.BigCloud
polygon.ModifiedDate = DateTime.Now

page.AnnotationsWidget.Add(polygon)
pdf.SaveToFile("Polygon_Annotation.pdf")