Back to Devexpress

PdfTextAnnotationFacade Class

officefileapi-devexpress-dot-pdf-f7a9a2a2.md

latest8.2 KB
Original Source

PdfTextAnnotationFacade Class

Contains members used to manage text annotations (sticky notes) 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 PdfTextAnnotationFacade :
    PdfMarkupAnnotationFacade
vb
Public Class PdfTextAnnotationFacade
    Inherits PdfMarkupAnnotationFacade

The following members return PdfTextAnnotationFacade objects:

Remarks

Create Text Annotations

The code sample below creates a sticky note at the specified point on the first page:

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

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

  // Add sticky note at the specified point
  PdfTextAnnotationFacade textAnnotation =
     page.AddTextAnnotation(new PdfPoint(64, 65), PdfTextAnnotationIconName.Cross);

  // Specify annotation parameters
  textAnnotation.Author = "Nancy Davolio";
  textAnnotation.Color = new PdfRGBColor(0.8, 0.2, 0.1);
  textAnnotation.Contents = "Please proofread this document";
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

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

  ' Add sticky note at the specified point
  Dim textAnnotation As PdfTextAnnotationFacade =
     page.AddTextAnnotation(New PdfPoint(64, 65), PdfTextAnnotationIconName.Cross)

  ' Specify annotation parameters
  textAnnotation.Author = "Nancy Davolio"
  textAnnotation.Color = New PdfRGBColor(0.8, 0.2, 0.1)
  textAnnotation.Contents = "Please proofread this document"
End Using

Edit Text Annotations

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

The code sample below retrieves all sticky notes on the first page and changes their icon, color and opacity:

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

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

  // Retrieve all sticky notes
  var stickyNotes = page.Annotations.Where
    (annotation => annotation.Type == PdfAnnotationType.Text);
  foreach (PdfTextAnnotationFacade stickyNote in stickyNotes)
  {
      // Change annotation parameters
      stickyNote.IconName = PdfTextAnnotationIconName.Note;
      stickyNote.Opacity = 0.7;
      stickyNote.Color = new PdfRGBColor(0.10, 0.85, 1.00);
  }
  // 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 page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all sticky notes
  Dim stickyNotes = page.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.Text)
  For Each stickyNote As PdfTextAnnotationFacade In stickyNotes
    ' Change annotation parameters
    stickyNote.IconName = PdfTextAnnotationIconName.Note
    stickyNote.Opacity = 0.7
    stickyNote.Color = New PdfRGBColor(0.10, 0.85, 1.00)
  Next stickyNote

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

Flatten Text 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 text annotations on the first page:

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

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

    // Flatten all text annotations
    page.FlattenAnnotations(PdfAnnotationType.Text);

    // 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 page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Flatten all text annotations
  page.FlattenAnnotations(PdfAnnotationType.Text)

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

Remove Text Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all sticky motes 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 page = processor.DocumentFacade.Pages[0];

  // Retrieve all sticky notes
  var stickyNotes = page.Annotations.Where
    (annotation => annotation.Type == PdfAnnotationType.Text).ToList();
  foreach (PdfTextAnnotationFacade stickyNote in stickyNotes)
  {
      // Remove each annotation
      stickyNote.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 page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all text annotations
  Dim stickyNotes = page.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.Text).ToList()
  For Each stickyNote As PdfTextAnnotationFacade In stickyNotes

    ' Remove each annotation
    stickyNote.Remove()
  Next stickyNote

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

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfTextAnnotationFacade

See Also

PdfTextAnnotationFacade Members

DevExpress.Pdf Namespace