Back to Devexpress

PdfPageFacade.AddTextAnnotation(PdfRectangle) Method

officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addtextannotation-x28-devexpress-dot-pdf-dot-pdfrectangle-x29.md

latest3.3 KB
Original Source

PdfPageFacade.AddTextAnnotation(PdfRectangle) Method

Adds a text annotation to the specified area on the page.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfTextAnnotationFacade AddTextAnnotation(
    PdfRectangle rect
)
vb
Public Function AddTextAnnotation(
    rect As PdfRectangle
) As PdfTextAnnotationFacade

Parameters

NameTypeDescription
rectPdfRectangle

A page area to add the text annotation.

|

Returns

TypeDescription
PdfTextAnnotationFacade

An object that contains text annotation properties.

|

Remarks

The code sample below creates a sticky note above a specific text:

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

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

  // Find the target phrase in a document
  string text = "Xbox";
  PdfTextSearchResults searchResults = processor.FindText(text);

  if (searchResults.Status == PdfTextSearchStatus.Found)
  {
      // Add a sticky note to this phrase
      PdfTextAnnotationFacade stickyNote =
          page.AddTextAnnotation(searchResults.Rectangles[0].BoundingRectangle);

      // Specify annotation properties
      stickyNote.Author = "Bill Smith";
      stickyNote.Subject = "Important!";
      stickyNote.Contents = "Please, fact-check this reference";
      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)

  ' Find the target phrase in a document
  Dim text As String = "Xbox"
  Dim searchResults As PdfTextSearchResults = processor.FindText(text)

  If searchResults.Status = PdfTextSearchStatus.Found Then

    ' Add a sticky note to this phrase
    Dim stickyNote As PdfTextAnnotationFacade =
       page.AddTextAnnotation(searchResults.Rectangles(0).BoundingRectangle)

    ' Specify annotation properties
    stickyNote.Author = "Bill Smith"
    stickyNote.Subject = "Important!"
    stickyNote.Contents = "Please, fact-check this reference"
    stickyNote.Color = New PdfRGBColor(0.10, 0.85, 1.00)
  End If
  ' Save the result
  processor.SaveDocument("..\\..\\Result.pdf");

End Using

See Also

PdfPageFacade Class

PdfPageFacade Members

DevExpress.Pdf Namespace