Back to Devexpress

PdfPageFacade.AddTextMarkupAnnotation(PdfOrientedRectangle, PdfTextMarkupAnnotationType) Method

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

latest5.6 KB
Original Source

PdfPageFacade.AddTextMarkupAnnotation(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(
    PdfOrientedRectangle textRectangle,
    PdfTextMarkupAnnotationType style
)
vb
Public Function AddTextMarkupAnnotation(
    textRectangle As PdfOrientedRectangle,
    style As PdfTextMarkupAnnotationType
) As PdfTextMarkupAnnotationFacade

Parameters

NameTypeDescription
textRectanglePdfOrientedRectangle

A rectangle that specifies a page area where the annotation should be located.

| | style | PdfTextMarkupAnnotationType |

The text markup annotation type.

|

Returns

TypeDescription
PdfTextMarkupAnnotationFacade

An object that contain text markup annotation properties.

|

Remarks

If a specified page area does not contain text, the AddTextMarkupAnnotation method returns null.

Example

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
  PdfDocumentFacade facade = processor.DocumentFacade;
  PdfPageFacade page = facade.Pages[0];

  // Find the target phrase in the document
  string strikeOutText = "Xbox";
  PdfTextSearchResults strikeSearchResults = processor.FindText(strikeOutText);

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

      // Add text markup annotation to this phrase
      PdfTextMarkupAnnotationFacade strikeOutAnnotation =
          page.AddTextMarkupAnnotation(strikeSearchResults.Rectangles[0], 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);
  }
}
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)

  ' Find the target phrase in the document
  Dim strikeOutText As String = "Xbox"
  Dim strikeSearchResults As PdfTextSearchResults = processor.FindText(strikeOutText)

  If strikeSearchResults.Status = PdfTextSearchStatus.Found Then

    ' Add text markup annotation to this phrase
    Dim strikeOutAnnotation As PdfTextMarkupAnnotationFacade =
       page.AddTextMarkupAnnotation(strikeSearchResults.Rectangles(0), 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
End Using

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddTextMarkupAnnotation(PdfOrientedRectangle, PdfTextMarkupAnnotationType) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-highlight-search-results/CS/HighlightSearchResults/Program.cs#L68

csharp
PdfTextMarkupAnnotationFacade annotation =
          page.AddTextMarkupAnnotation(result.Rectangles[i], PdfTextMarkupAnnotationType.Highlight);
if (annotation != null)

pdf-document-api-highlight-search-results/VB/HighlightSearchResults/Program.vb#L57

vb
For i As Integer = 0 To result.Rectangles.Count - 1
    Dim annotation As PdfTextMarkupAnnotationFacade = page.AddTextMarkupAnnotation(result.Rectangles(i), PdfTextMarkupAnnotationType.Highlight)
    If annotation IsNot Nothing Then

See Also

PdfPageFacade Class

PdfPageFacade Members

DevExpress.Pdf Namespace