PDF Mosaic: How to add polygon annotation to PDF documents


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code

 

This sample shows how to add polygon annotations to your PDF document.

Use PDFPolygonAnnotation class to add polygon annotation.

Use PDFPolygonAnnotation class to add polygon annotation in PDF Mosaic
 

using PDFMosaic;
using System;
using System.Drawing;
 
namespace PDFPolygonAnnotationSample
{
    class PDFPolygonAnnotationSample
    {
        static void Main()
        {
            PDFDocument pdf = new PDFDocument();
            pdf.Pages.Add(new PDFPage(PDFPaperFormat.A4));
            Random rnd = new Random();
            PDFInkList list = new PDFInkList();
            PointF[] f = new PointF[10];
            for (int j = 0; j < 10; ++j)
            {
                int min = rnd.Next(100);
                int max = rnd.Next(100, 600);
                for (int i = 0; i < f.Length; ++i)
                {
                    f[i].X = rnd.Next(min, max);
                    f[i].Y = rnd.Next(min, max);
 
                }
                list.AddArray(new PDFPointsArray(f));
            }
            PDFPolygonAnnotation annotation = new PDFPolygonAnnotation(list[0]);
            PDFPolylineAnnotation annotation1 = new PDFPolylineAnnotation(list[1]);
            annotation1.StartLineStyle = PDFLineEndingStyle.Circle;
            annotation1.EndLineStyle = PDFLineEndingStyle.RClosedArrow;
            annotation1.BackgroundColor = new PDFColorRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
            annotation1.Contents = "PDF polygon annotation";
            annotation.BackgroundColor = new PDFColorRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
            annotation.Color = new PDFColorRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
            annotation1.Color = new PDFColorRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
            annotation1.Contents = "PDF polyline annotation";
            pdf.Pages[0].Annotations.Add(annotation);
            pdf.Pages[0].Annotations.Add(annotation1);
            pdf.Save("TestPolygonAndPolylineAnnotation.pdf", true);
        }
    }
}

 


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code