Back to Devexpress

PdfPolyLineAnnotationFacade Class

officefileapi-devexpress-dot-pdf-bfc08cba.md

latest9.0 KB
Original Source

PdfPolyLineAnnotationFacade Class

Contains members used to manage polyline 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 PdfPolyLineAnnotationFacade :
    PdfPathAnnotationFacade
vb
Public Class PdfPolyLineAnnotationFacade
    Inherits PdfPathAnnotationFacade

The following members return PdfPolyLineAnnotationFacade objects:

Remarks

Create Polyline Annotations

The code sample below creates a polyline annotation:

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Define polyline vertices
    PdfPoint point1 = new PdfPoint(100, 100);
    PdfPoint point2 = new PdfPoint(110, 110);
    PdfPoint point3 = new PdfPoint(120, 100);
    PdfPoint point4 = new PdfPoint(130, 110);
    PdfPoint point5 = new PdfPoint(140, 100);
    PdfPoint[] points = new PdfPoint[] { point1, point2, point3, point4, point5 };

    // Create an annotation
    PdfPolyLineAnnotationFacade polylineAnnotation = pageFacade.AddPolyLineAnnotation(points);

    // Specify annotation parameters
    polylineAnnotation.Author = "Rayn Anita W";
    polylineAnnotation.Contents = "Made in PDF Document API";
    polylineAnnotation.BorderWidth = 6;
    polylineAnnotation.Color = new PdfRGBColor(0.8, 0.2, 0.1);

    // 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 polyline vertices
    Dim point1 As New PdfPoint(100, 100)
    Dim point2 As New PdfPoint(110, 110)
    Dim point3 As New PdfPoint(120, 100)
    Dim point4 As New PdfPoint(130, 110)
    Dim point5 As New PdfPoint(140, 100)
    Dim points() As PdfPoint = { point1, point2, point3, point4, point5 }

    ' Create an annotation
    Dim polylineAnnotation As PdfPolyLineAnnotationFacade = pageFacade.AddPolyLineAnnotation(points)

    ' Specify annotation parameters
    polylineAnnotation.Author = "Rayn Anita W"
    polylineAnnotation.Contents = "Made in PDF Document API"
    polylineAnnotation.BorderWidth = 6
    polylineAnnotation.Color = New PdfRGBColor(0.8, 0.2, 0.1)

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

Edit Polyline Annotations

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

The code sample below retrieves all polyline annotations on the first page and changes their border and endings’ style:

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Obtain all polyline annotations
    var polyLines = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.PolyLine);
    foreach (PdfPolyLineAnnotationFacade polyLine in polyLines) 
    {
        // Change annotation parameters
        polyLine.BorderStyle = PdfBorderStyle.Dot;
        polyLine.LineEndStyle = PdfAnnotationLineEndingStyle.Butt;
        polyLine.LineStartStyle = PdfAnnotationLineEndingStyle.Butt;
        polyLine.BorderWidth = 3;
    }
    // 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)

  ' Obtain all polyline annotations
  Dim polyLines = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.PolyLine)
  For Each polyLine As PdfPolyLineAnnotationFacade In polyLines

    ' Change annotation parameters
    polyLine.BorderStyle = PdfBorderStyle.Dot
    polyLine.LineEndStyle = PdfAnnotationLineEndingStyle.Butt
    polyLine.LineStartStyle = PdfAnnotationLineEndingStyle.Butt
    polyLine.BorderWidth = 3
  Next polyLine
  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Flatten Polyline 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 polyline annotations on the first page:

csharp
using DevExpress.Pdf;

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 polyline annotations
    pageFacade.FlattenAnnotations(PdfAnnotationType.PolyLine);

    // 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 polyline annotations
  pageFacade.FlattenAnnotations(PdfAnnotationType.PolyLine)

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

Remove Polyline Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all polyline annotations from 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];

    // Obtain all polyline annotations
    var polyLines = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.PolyLine).ToList();
    foreach (PdfPolyLineAnnotationFacade polyline in polyLines) 
    {
        // Remove all polyline annotations
        polyline.Remove();
    }
    // 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)

  ' Obtain all polyline annotations
  Dim polyLines = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.PolyLine).ToList()
  For Each polyline As PdfPolyLineAnnotationFacade In polyLines
    ' Remove all polyline annotations
    polyline.Remove()
  Next polyline
  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfPathAnnotationFacade PdfPolyLineAnnotationFacade

See Also

PdfPolyLineAnnotationFacade Members

DevExpress.Pdf Namespace