TextMarkupAnnotation Class
Defines a text markup annotation in a PDF document.
Declaration
public class TextMarkupAnnotation extends MarkupAnnotation
Remarks
Use text markup annotations to identify or comment on document content. You can highlight text, underline important information, or strike out obsolete content.
The following code snippet highlights all occurrences of “external PDF Viewer“:
import com.devexpress.docs.pdf.*;
import java.nio.file.*;
import java.nio.channels.*;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
try (FileChannel channel = FileChannel.open(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(channel)) {
// Search for text.
for (TextSearchInfo result : pdfDocument.findText("external PDF Viewer")) {
for (TextMatchInfo match : result.getMatches()) {
List<OrientedRectangle> bounds =
match.getMatchFragments().stream()
.map(fragment -> fragment.getRectangle())
.toList();
TextMarkupAnnotation annotation = new TextMarkupAnnotation(bounds);
annotation.setType(TextMarkupAnnotationType.HIGHLIGHT);
annotation.setColor(PdfColor.getYellow());
annotation.setTitle("John Smith");
annotation.setContent("Review this section.");
pdfDocument.getPages()
.get(result.getPageIndex())
.getAnnotations()
.add(annotation);
}
}
// Save the document.
try (WritableByteChannel summaryChannel =
FileChannel.open(
Path.of("Result.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(summaryChannel);
}
}
}
}
Refer to the following help topic for additional information: Text Markup Annotations.
Inherited Members
Inheritance
Constructors
TextMarkupAnnotation(List<Quadrilateral> quads) Constructor
Initializes a new instance of the TextMarkupAnnotation class with specified quadrilateral points.
Declaration
public TextMarkupAnnotation(List<Quadrilateral> quads)
Parameters
| Name | Type | Description |
|---|---|---|
| quads | java.util.List<Quadrilateral> | Quadrilateral points that define the text markup annotation area. |
TextMarkupAnnotation(OrientedRectangle[] rectangles) Constructor
Initializes a new instance of the TextMarkupAnnotation class with specified rectangles.
Declaration
public TextMarkupAnnotation(OrientedRectangle[] rectangles)
Parameters
| Name | Type | Description |
|---|---|---|
| rectangles | OrientedRectangle[] | An array of rectangles that define the text markup annotation bounds. |
Methods
getQuads() Method
Returns quadrilateral points that define the text markup annotation area.
Declaration
public List<Quadrilateral> getQuads()
Returns
| Type | Description |
|---|---|
| java.util.List<Quadrilateral> | Quadrilateral points that define the text markup annotation area. |
getType() Method
Returns the text markup annotation type.
Declaration
public TextMarkupAnnotationType getType()
Returns
| Type | Description |
|---|---|
| TextMarkupAnnotationType | The text markup annotation type. |
setQuads(List<Quadrilateral> value) Method
Sets quadrilateral points that define the text markup annotation area.
Declaration
public void setQuads(List<Quadrilateral> value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | java.util.List<Quadrilateral> | Quadrilateral points that define the text markup annotation area. |
setType(TextMarkupAnnotationType value) Method
Sets the text markup annotation type.
Declaration
public void setType(TextMarkupAnnotationType value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | TextMarkupAnnotationType | The text markup annotation type. |