Skip to main content
.NET Framework 4.5.2+

PdfGraphics.DrawPolygon(Pen, PointF[]) Method

Draws a polygon by points from the specified array.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v22.2.Drawing.dll

NuGet Package: DevExpress.Pdf.Drawing

Declaration

public void DrawPolygon(
    Pen pen,
    PointF[] points
)

Parameters

Name Type Description
pen Pen

A Pen object that specifies the color, width, and style of the polygon.

points PointF[]

An array of PointF structures that specify the polygon vertices (in world coordinate system).

Remarks

The first two points of the points array specify the first polygon side. Each next side connects the previous side’s end point and the next array point. If the first and last array points are different, they specify the last polygon side. Pass the points and pen parameters to the DrawPolygon method to draw a polygon.

To draw a shape on the PDF page, use one of the following methods:

PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackground
These methods allow you to draw content on an existing page.
PdfDocumentProcessor.RenderNewPage
Draws content on a new page.

The code sample below draws a polygon by seven points.

Draw a Polygon

using DevExpress.Pdf;
using System.Drawing;
//...

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument();
    PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
        using (PdfGraphics graphics = processor.CreateGraphics())
        {
            // Create a point array.
            PointF[] points = new PointF[] 
            { 
                new PointF(50, 50), 
                new PointF(200, 10), 
                new PointF(450, 150), 
                new PointF(500, 200), 
                new PointF(520, 350), 
                new PointF(570, 650), 
                new PointF(500, 700) 
            };

            // Draw a polygon.
            using (var pen = new Pen(Color.Red, 5))
                graphics.DrawPolygon(pen, points);

            // Add graphics content to the document page.
            graphics.AddToPageForeground(page, 72, 72);
        }
    processor.SaveDocument("out2.pdf");
}
Process.Start("out.pdf");
See Also