Back to Devexpress

PdfLineAnnotationFacade Class

officefileapi-devexpress-dot-pdf-fa1c1121.md

latest8.9 KB
Original Source

PdfLineAnnotationFacade Class

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

The following members return PdfLineAnnotationFacade objects:

Remarks

Create Line Annotations

The code sample below creates a red line 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 an annotation's start and end points
    PdfPoint start = new PdfPoint(100, 100);
    PdfPoint end = new PdfPoint(150, 100);

    // Add a line annotation
    PdfLineAnnotationFacade lineAnnotation = pageFacade.AddLineAnnotation(start, end);

    // Specify the annotation parameters
    lineAnnotation.Author = "Brian Zetc";
    lineAnnotation.BorderStyle = PdfBorderStyle.DashDot;
    lineAnnotation.BorderWidth = 3;
    lineAnnotation.Color = new PdfRGBColor(0.8, 0.2, 0.1);
    lineAnnotation.Contents = "Made in PDF Document API";

    // 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 an annotation's start and end points
  Dim start As New PdfPoint(100, 100)
  Dim [end] As New PdfPoint(150, 100)

  ' Add a line annotation
  Dim lineAnnotation As PdfLineAnnotationFacade = pageFacade.AddLineAnnotation(start, [end])

  ' Specify the annotation parameters
  lineAnnotation.Author = "Brian Zetc"
  lineAnnotation.BorderStyle = PdfBorderStyle.DashDot
  lineAnnotation.BorderWidth = 3
  lineAnnotation.Color = New PdfRGBColor(0.8, 0.2, 0.1)
  lineAnnotation.Contents = "Made in PDF Document API"

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

Edit Line Annotations

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

The code sample below retrieves all line annotations on the first page and changes their end style and interior color used to fill the annotation’s line endings:

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 line annotations
    var lineAnnotations = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.Line);
    foreach (PdfLineAnnotationFacade lineAnnotation in lineAnnotations) 
    {
        // Change each line's interior color and ending style
        lineAnnotation.InteriorColor = new PdfRGBColor(0.8, 0.2, 0.1);
        lineAnnotation.LineStartStyle = PdfAnnotationLineEndingStyle.Diamond;
        lineAnnotation.LineEndStyle = PdfAnnotationLineEndingStyle.ClosedArrow;
    }

    // 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 line annotations
  Dim lineAnnotations = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.Line)
  For Each lineAnnotation As PdfLineAnnotationFacade In lineAnnotations

    ' Change each line's interior color and ending styles
    lineAnnotation.InteriorColor = New PdfRGBColor(0.8, 0.2, 0.1)
    lineAnnotation.LineStartStyle = PdfAnnotationLineEndingStyle.Diamond
    lineAnnotation.LineEndStyle = PdfAnnotationLineEndingStyle.ClosedArrow
  Next lineAnnotation

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

Flatten Line 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 line 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 line annotations
    pageFacade.FlattenAnnotations(PdfAnnotationType.Line);

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

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

Remove Line Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all line annotations on 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 line annotations
    var lineAnnotations = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.Line).ToList();
    foreach (PdfLineAnnotationFacade lineAnnotation in lineAnnotations) 
    {
        // Remove all annotations
        lineAnnotation.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 line annotations
  Dim lineAnnotations = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.Line).ToList()
  For Each lineAnnotation As PdfLineAnnotationFacade In lineAnnotations
    ' Remove all annotations
    lineAnnotation.Remove()
  Next lineAnnotation

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

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfPathAnnotationFacade PdfLineAnnotationFacade

See Also

PdfLineAnnotationFacade Members

DevExpress.Pdf Namespace