Back to Devexpress

PdfPageFacade.AddTextMarkupAnnotation(IEnumerable<PdfOrientedRectangle>, PdfTextMarkupAnnotationType) Method

officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addtextmarkupannotation-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-pdf-dot-pdforientedrectangle-devexpress-dot-pdf-dot-pdftextmarkupannotationtype-x29.md

latest4.5 KB
Original Source

PdfPageFacade.AddTextMarkupAnnotation(IEnumerable<PdfOrientedRectangle>, PdfTextMarkupAnnotationType) Method

Creates a text markup annotation at the specified page area.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfTextMarkupAnnotationFacade AddTextMarkupAnnotation(
    IEnumerable<PdfOrientedRectangle> textRectangles,
    PdfTextMarkupAnnotationType style
)
vb
Public Function AddTextMarkupAnnotation(
    textRectangles As IEnumerable(Of PdfOrientedRectangle),
    style As PdfTextMarkupAnnotationType
) As PdfTextMarkupAnnotationFacade

Parameters

NameTypeDescription
textRectanglesIEnumerable<PdfOrientedRectangle>

A collection of rectangles that specify a page area where the annotation should be located.’

| | style | PdfTextMarkupAnnotationType |

The text markup annotation type.

|

Returns

TypeDescription
PdfTextMarkupAnnotationFacade

An object that contains text markup annotation properties.

|

Remarks

This method returns null if the collection of PdfOrientedRectangle objects is empty.

The following code snippet highlights specific text in the document:

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

  // Access the first page's properties
  PdfPageFacade page = pdfDocumentProcessor.DocumentFacade.Pages[0];

  // Find the phrase to highlight
  string annotatedText =
    "We estimate that each component of Ounce provides independent pseudorandom theory.";
  PdfTextSearchResults searchResults = pdfDocumentProcessor.FindText(annotatedText);

  if (searchResults.Status == PdfTextSearchStatus.Found)
  {
      // Highlight found text
      PdfTextMarkupAnnotationFacade textMarkupAnnotation =
          page.AddTextMarkupAnnotation(searchResults.Rectangles, PdfTextMarkupAnnotationType.Highlight);

      // Specify annotation properties
      textMarkupAnnotation.Author = "Bill Smith";
      textMarkupAnnotation.Subject = "Important!";
      textMarkupAnnotation.Contents = "Please, fact-check this diagram";
      textMarkupAnnotation.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's properties
  Dim page As PdfPageFacade = pdfDocumentProcessor.DocumentFacade.Pages(0)

  ' Find the phrase to highlight
  Dim annotatedText As String = "We estimate that each component of Ounce provides independent pseudorandom theory."
  Dim searchResults As PdfTextSearchResults = pdfDocumentProcessor.FindText(annotatedText)

  If searchResults.Status = PdfTextSearchStatus.Found Then

  ' Highlight found text
    Dim textMarkupAnnotation As PdfTextMarkupAnnotationFacade = page.AddTextMarkupAnnotation(searchResults.Rectangles, PdfTextMarkupAnnotationType.Highlight)

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