Add text field annotation

On this page

Text field annotation adds a rectangle with a text as shown in the picture below:

You can use the following methods to set the properties of the TextFieldAnnotation class:

To add a text field annotation, follow these steps: 

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the TextFieldAnnotation class. Specify the appropriate properties (position, page number, etc).
  3. Call the add() method. Specify the TextFieldAnnotation class.
  4. Call the save() method. Specify the output document path or stream.

The following code snippet shows how to add TextFieldAnnotation to the document:

// This example demonstrates adding text field annotation.

// Create an instance of Annotator class
Annotator annotator = new Annotator("inputPath");
try {
    // Create an instance of Reply class and add comments
    Reply reply1 = new Reply();
    reply1.setComment("First comment");
    reply1.setRepliedOn(Calendar.getInstance().getTime());

    Reply reply2 = new Reply();
    reply2.setComment("Second comment");
    reply2.setRepliedOn(Calendar.getInstance().getTime());

    java.util.List<Reply> replies =  new ArrayList<Reply>();
    replies.add(reply1);
    replies.add(reply2);

    // Create an instance of TextFieldAnnotation class and set options
    TextFieldAnnotation textField = new TextFieldAnnotation();
    textField.setBackgroundColor(65535);
    textField.setBox(new Rectangle(100, 100, 100, 100));
    textField.setCreatedOn(Calendar.getInstance().getTime());
    textField.setText("Some text");
    textField.setFontColor(65535);
    textField.setFontSize((double)12);
    textField.setMessage("This is text field annotation");
    textField.setOpacity(0.7);
    textField.setPageNumber(0);
    textField.setPenStyle(PenStyle.Dot);
    textField.setPenWidth((byte) 3);
    textField.setReplies(replies);
    
    // Add annotation and save to file
    annotator.add(textField);
    annotator.save("outputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}

On this page