Back to Devexpress

PdfPolygonAnnotationFacade Class

officefileapi-devexpress-dot-pdf-3feee3fc.md

latest8.7 KB
Original Source

PdfPolygonAnnotationFacade Class

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

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfPolygonAnnotationFacade :
    PdfPathAnnotationFacade
vb
Public Class PdfPolygonAnnotationFacade
    Inherits PdfPathAnnotationFacade

The following members return PdfPolygonAnnotationFacade objects:

Remarks

Create Polygon Annotations

The code sample below creates a hexagon:

csharp
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");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Define hexagon vertices
  Dim point1 As New PdfPoint(150, 150)
  Dim point2 As New PdfPoint(140, 160)
  Dim point3 As New PdfPoint(150, 170)
  Dim point4 As New PdfPoint(160, 170)
  Dim point5 As New PdfPoint(170, 160)
  Dim point6 As New PdfPoint(160, 150)
  Dim points() As PdfPoint = { point1, point2, point3, point4, point5, point6 }

  ' Create a hexagon
  Dim hexagon As PdfPolygonAnnotationFacade = pageFacade.AddPolygonAnnotation(points)
  hexagon.Author = "Cardle Anita W"

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

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:

csharp
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");
}
vb
Imports DevExpress.Pdf
Imports System.Linq

Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all polygon annotations
  Dim polygons = pageFacade.Annotations.Where(Function(annotation) annotation.Type = PdfAnnotationType.Polygon)
  For Each polygon As PdfPolygonAnnotationFacade 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"
  Next polygon

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Flatten Polygon Annotations

Call one of the following methods to flatten an annotation:

MethodDescription
PdfDocumentFacade.FlattenAnnotationsFlattens document annotations.
PdfPageFacade.FlattenAnnotationsFlattens annotations of a specific page.
PdfAnnotationFacade.Flatten()Flattens a specific annotation.

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

csharp
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");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Flatten all polygon annotations
  pageFacade.FlattenAnnotations(PdfAnnotationType.Polygon)

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Remove Polygon Annotations

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

csharp
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");
}
vb
Imports DevExpress.Pdf
Imports System.Linq

Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all polygon annotations
  Dim polygons = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.Polygon).ToList()
  For Each polygon As PdfPolygonAnnotationFacade In polygons
    ' Remove all polygons
    polygon.Remove()
  Next polygon

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfPathAnnotationFacade PdfPolygonAnnotationFacade

See Also

PdfPolygonAnnotationFacade Members

DevExpress.Pdf Namespace