Skip to main content
All docs
V25.1
  • PdfPolygonAnnotationFacade Class

    Contains members used to manage polygon annotations without access to their inner structure.

    Namespace: DevExpress.Pdf

    Assembly: DevExpress.Pdf.v25.1.Core.dll

    NuGet Package: DevExpress.Pdf.Core

    Declaration

    public class PdfPolygonAnnotationFacade :
        PdfPathAnnotationFacade

    The following members return PdfPolygonAnnotationFacade objects:

    Remarks

    Create Polygon Annotations

    The code sample below creates a hexagon:

    hexagon

    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("..\\..\\Document.pdf");
    
        // Access the firs page properties
        PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
        // Define hexagon vertices
        PdfPoint point1 = new PdfPoint(150, 150);
        PdfPoint point2 = new PdfPoint(140, 160);
        PdfPoint point3 = new PdfPoint(150, 170);
        PdfPoint point4 = new PdfPoint(160, 170);
        PdfPoint point5 = new PdfPoint(170, 160);
        PdfPoint point6 = new PdfPoint(160, 150);
        PdfPoint[] points = new PdfPoint[] { point1, point2, point3, point4, point5, point6 };
    
        // Create a hexagon annotation
        PdfPolygonAnnotationFacade hexagon = pageFacade.AddPolygonAnnotation(points);
        hexagon.Author = "Cardle Anita W";
    
        // Save the result
        processor.SaveDocument("..\\..\\Result.pdf");
    }
    

    Edit Polygon Annotations

    The PdfPageFacade.Annotations property returns all page annotation properties. You can filter polygon annotation properties, cast them to the PdfPolygonAnnotationFacade class, and use class properties to modify annotation parameters.

    The code sample below retrieves all polygon annotations on the first page and changes their parameters:

    polygon edited

    using DevExpress.Pdf;
    using System.Linq;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("..\\..\\Document.pdf");
    
        // Access the first page properties
        PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
        // Retrieve all polygon annotations
        var polygons = pageFacade.Annotations.Where
          (annotation => annotation.Type == PdfAnnotationType.Polygon);
        foreach (PdfPolygonAnnotationFacade polygon in polygons) 
        {
            // Change polygon parameters
            polygon.BorderWidth = 4;
            polygon.InteriorColor = new PdfRGBColor(0.40, 0.90, 1.00);
            polygon.Color = new PdfRGBColor(0.20, 0.20, 1.00);
            polygon.Contents = "Made by PDF Document API";
        }
    
        // Save the result
        processor.SaveDocument("..\\..\\Result.pdf");
    }
    

    Flatten Polygon Annotations

    Call one of the following methods to flatten an annotation:

    Method Description
    PdfDocumentFacade.FlattenAnnotations Flattens document annotations.
    PdfPageFacade.FlattenAnnotations Flattens annotations of a specific page.
    PdfAnnotationFacade.Flatten() Flattens a specific annotation.

    The code sample below flattens all polygon annotations on the first page:

    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("..\\..\\Document.pdf");
    
        // Access the first page properties
        PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
        // Flatten all polygon annotations
        pageFacade.FlattenAnnotations(PdfAnnotationType.Polygon);
    
        // Save the result
        processor.SaveDocument("..\\..\\Result.pdf");
    }
    

    Remove Polygon Annotations

    Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all polygon annotations from the first page:

    using DevExpress.Pdf;
    using System.Linq;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Load a document
        processor.LoadDocument("..\\..\\Document.pdf");
    
        // Access the first page properties
        PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
        // Retrieve all polygon annotations
        var polygons = pageFacade.Annotations.Where
          (annotation => annotation.Type == PdfAnnotationType.Polygon).ToList();
        foreach (PdfPolygonAnnotationFacade polygon in polygons) 
        {
            // Remove all polygons
            polygon.Remove();
        }
    
        // Save the result
        processor.SaveDocument("..\\..\\Result.pdf");
    }
    
    See Also