VintaSoft Imaging .NET SDK 11.0
Vintasoft.Imaging.Pdf.Tree.Annotations Namespace / PdfPolygonAnnotation Class
Members Example



In This Topic
    PdfPolygonAnnotation Class
    In This Topic
    Represents a PDF annotation that displays a polygon.
    Object Model
    PdfPolygonAnnotation ClassPdfAction ClassPdfAnnotationAdditionalActions ClassPdfAnnotationAppearanceGenerator ClassAffineMatrix ClassPdfAnnotationAppearances ClassPdfFileReferenceSpecificationList ClassPdfFileReferenceSpecification ClassPdfBasicObject ClassPdfAnnotationBorderEffect ClassPdfAnnotationBorderStyle ClassPdfDocument ClassPdfIndirectReference ClassPdfOptionalContentGroup ClassPdfPage ClassPdfPopupAnnotation ClassPdfAnnotation Class
    Syntax
    'Declaration
     
    Public NotInheritable Class PdfPolygonAnnotation 
       Inherits PdfPolygonalAnnotation
    public sealed class PdfPolygonAnnotation : PdfPolygonalAnnotation 
    public __gc __sealed class PdfPolygonAnnotation : public PdfPolygonalAnnotation 
    public ref class PdfPolygonAnnotation sealed : public PdfPolygonalAnnotation 
    Example
    Here is an example that shows how to create a PDF polygon annotation:
    ''' <summary>
    ''' Creates the PDF documenet with polygon annotation.
    ''' </summary>
    ''' <param name="outputPdfFilename">The output PDF filename.</param>
    Public Shared Sub CreatePdfPolygonAnnotation(outputPdfFilename As String)
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(outputPdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14)
            Dim page As Vintasoft.Imaging.Pdf.Tree.PdfPage
                
            ' Add new page
            page = document.Pages.Add(Vintasoft.Imaging.PaperSizeKind.A4)
            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
            Dim annotationRectangle As System.Drawing.RectangleF = page.MediaBox
            annotationRectangle.Inflate(-200, -300)
                
            ' Points
            Dim random As New System.Random()
            Dim polylgonalAnnotationPoints As System.Drawing.PointF() = New System.Drawing.PointF(9) {}
            polylgonalAnnotationPoints(0) = annotationRectangle.Location
            For i As Integer = 1 To polylgonalAnnotationPoints.Length - 1
                polylgonalAnnotationPoints(i) = New System.Drawing.PointF(annotationRectangle.X + annotationRectangle.Width * CSng(random.NextDouble()), annotationRectangle.Y + annotationRectangle.Height * CSng(random.NextDouble()))
            Next
                
            ' Polygon annotation
            Dim polygon As New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolygonAnnotation(page)
            polygon.BorderWidth = 3
            polygon.Rectangle = System.Drawing.RectangleF.Inflate(annotationRectangle, polygon.BorderWidth, polygon.BorderWidth)
            polygon.Points = polylgonalAnnotationPoints
            polygon.InteriorColor = System.Drawing.Color.Red
            polygon.Color = System.Drawing.Color.Green
            polygon.UpdateAppearance()
            page.Annotations.Add(polygon)
                
            document.SaveChanges()
        End Using
    End Sub
    /// <summary>
    /// Creates the PDF documenet with polygon annotation.
    /// </summary>
    /// <param name="outputPdfFilename">The output PDF filename.</param>
    public static void CreatePdfPolygonAnnotation(string outputPdfFilename)
    {
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(
            outputPdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14))
        {
            Vintasoft.Imaging.Pdf.Tree.PdfPage page;
                
            // Add new page
            page = document.Pages.Add(Vintasoft.Imaging.PaperSizeKind.A4);
            page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
            System.Drawing.RectangleF annotationRectangle = page.MediaBox;
            annotationRectangle.Inflate(-200, -300);
                
            // Points
            System.Random random = new System.Random();
            System.Drawing.PointF[] polylgonalAnnotationPoints = new System.Drawing.PointF[10];
            polylgonalAnnotationPoints[0] = annotationRectangle.Location;
            for (int i = 1; i < polylgonalAnnotationPoints.Length; i++)
            {
                polylgonalAnnotationPoints[i] = new System.Drawing.PointF(
                    annotationRectangle.X + annotationRectangle.Width * (float)random.NextDouble(),
                    annotationRectangle.Y + annotationRectangle.Height * (float)random.NextDouble());
            }
                
            // Polygon annotation
            Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolygonAnnotation polygon = 
                new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolygonAnnotation(page);
            polygon.BorderWidth = 3;
            polygon.Rectangle = System.Drawing.RectangleF.Inflate(annotationRectangle,
                polygon.BorderWidth, polygon.BorderWidth);
            polygon.Points = polylgonalAnnotationPoints;
            polygon.InteriorColor = System.Drawing.Color.Red;
            polygon.Color = System.Drawing.Color.Green;
            polygon.UpdateAppearance();
            page.Annotations.Add(polygon);
                
            document.SaveChanges();
        }
    }
    Inheritance Hierarchy
    Requirements

    Target Platforms: .NET 6; .NET 5; .NET Core 3.1; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also