How to: Add a Text Markup Annotation to a PDF Document
- 2 minutes to read
Important
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.
This example shows how to create a text markup annotation that highlights a text in a PDF document and specify the annotation properties.
To add a text markup annotation to a page, call one of PdfDocumentProcessor.AddTextMarkupAnnotation overload methods, where specify the page number and a page area corresponding to a text that should be annotated on this page. Note that if a specified page area does not correspond to a text on the page, the annotation is not created and PdfDocumentProcessor.AddTextMarkupAnnotation overload methods return null.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-add-a-text-markup-annotation-to-pdf-T545395
Imports System
Imports DevExpress.Pdf
Namespace CreateMarkupAnnotation
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Create a PDF Document Processor.
Using processor As New PdfDocumentProcessor()
' Load a document.
processor.LoadDocument("..\..\Document.pdf")
' Add a text markup annotation to the first page for a text corresponding to the specified page area.
Dim annot As PdfTextMarkupAnnotationData = processor.AddTextMarkupAnnotation(1, New PdfRectangle(90, 100, 240, 230), PdfTextMarkupAnnotationType.Highlight)
If annot IsNot Nothing Then
' Specify the annotation properties.
annot.Author = "Bill Smith"
annot.Contents = "Note"
annot.Color = New PdfRGBColor(0.8, 0.2, 0.1)
' Save the result document.
processor.SaveDocument("..\..\Result.pdf")
Else
Console.WriteLine("The annotation cannot be added to a page. Make sure, a specified page area corresponds to a text on the page.")
End If
End Using
End Sub
End Class
End Namespace