Skip to main content

CaretAnnotation Class

Defines a caret annotation in a PDF document.

Declaration

public class CaretAnnotation extends MarkupAnnotation

Remarks

The following code snippet creates a caret annotation, specifies its comment, and adds the annotation to a page:

package pdf;

import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;

import java.nio.channels.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (FileChannel fileChannel = FileChannel.open(Path.of("Document.pdf"));
             PdfDocument pdfDocument = new PdfDocument(fileChannel)) {

            Page page = pdfDocument.getPages().getFirst();

            createCaretAnnotation(page);

            // Save the document.
            try (WritableByteChannel channel =
                        FileChannel.open(Path.of("Result.pdf"),
                                StandardOpenOption.CREATE,
                                StandardOpenOption.WRITE,
                                StandardOpenOption.TRUNCATE_EXISTING)) {

                pdfDocument.save(channel);
            }
        }
    }

    static void createCaretAnnotation(Page page) {
        CaretAnnotation annotation =
                new CaretAnnotation(
                        new RectangleF(70, 350, 18, 18));

        annotation.setTitle("John Smith");
        annotation.setSubject("Editorial Review");
        annotation.setContent("Insert a new paragraph.");
        annotation.setColor(PdfColor.getGreen());
        annotation.setOpacity(0.8);

        page.getAnnotations().add(annotation);
    }
}

The following screenshot illustrates the result:

Caret Annotation, DevExpress PDF Document API for Java

Refer to the following help topic for additional information: Caret Annotations.

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
JavaObject

CaretAnnotation(RectangleF bounds)

Initializes a new instance of the CaretAnnotation class with specified bounds.

Declaration

public CaretAnnotation(RectangleF bounds)

Parameters

Name Type Description
bounds RectangleF

The annotation bounds.