Back to Devexpress

PdfPageFacade.AddTextMarkupAnnotation(PdfRectangle, PdfTextMarkupAnnotationType) Method

officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addtextmarkupannotation-x28-devexpress-dot-pdf-dot-pdfrectangle-devexpress-dot-pdf-dot-pdftextmarkupannotationtype-x29.md

latest4.1 KB
Original Source

PdfPageFacade.AddTextMarkupAnnotation(PdfRectangle, PdfTextMarkupAnnotationType) Method

Creates a text markup annotation for the text located in the specified page rectangle.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfTextMarkupAnnotationFacade AddTextMarkupAnnotation(
    PdfRectangle rectangle,
    PdfTextMarkupAnnotationType style
)
vb
Public Function AddTextMarkupAnnotation(
    rectangle As PdfRectangle,
    style As PdfTextMarkupAnnotationType
) As PdfTextMarkupAnnotationFacade

Parameters

NameTypeDescription
rectanglePdfRectangle

The rectangle with the text that should be annotated.

| | style | PdfTextMarkupAnnotationType |

The text markup annotation type.

|

Returns

TypeDescription
PdfTextMarkupAnnotationFacade

An object that contain text markup annotation properties.

|

Remarks

If a specified rectangle does not contain text, the annotation is not created and the method returns null.

Example: Strike Out Text

The code sample below strikes out specific text in the document:

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 strikeOutText = "Xbox";
  PdfTextSearchResults strikeSearchResults = processor.FindText(strikeOutText);

  if (strikeSearchResults.Status == PdfTextSearchStatus.Found)
  {

      // Add a text annotation to this phrase
      PdfTextMarkupAnnotationFacade strikeOutAnnotation =
          page.AddTextMarkupAnnotation(strikeSearchResults.Rectangles[0].BoundingRectangle, PdfTextMarkupAnnotationType.StrikeOut);

      // Specify annotation properties
      strikeOutAnnotation.Author = "Bill Smith";
      strikeOutAnnotation.Subject = "Important!";
      strikeOutAnnotation.Contents = "Please, fact-check this reference";
      strikeOutAnnotation.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 strikeOutText As String = "Xbox"
  Dim strikeSearchResults As PdfTextSearchResults = processor.FindText(strikeOutText)

  If strikeSearchResults.Status = PdfTextSearchStatus.Found Then

    ' Add a text annotation to this phrase
    Dim strikeOutAnnotation As PdfTextMarkupAnnotationFacade = page.AddTextMarkupAnnotation(strikeSearchResults.Rectangles(0).BoundingRectangle, PdfTextMarkupAnnotationType.StrikeOut)

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