Add strikeout annotation

On this page

Strikeout annotation strike-throughs a text fragment as shown in the picture below:

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

To add a strikeout annotation, follow these steps:

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

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

// This example demonstrates adding text strikeout 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);

    Point point1 = new Point(80, 730);
    Point point2 = new Point(240, 730);
    Point point3 = new Point(80, 650);
    Point point4 = new Point(240, 650);

    List<Point> points = new ArrayList<Point>();
    points.add(point1);
    points.add(point2);
    points.add(point3);
    points.add(point4);

    // Create an instance of StrikeoutAnnotation class and set options
    StrikeoutAnnotation strikeout = new StrikeoutAnnotation();
    strikeout.setCreatedOn(Calendar.getInstance().getTime());
    strikeout.setFontColor(65535);
    strikeout.setMessage("This is strikeout annotation");
    strikeout.setOpacity(0.7);
    strikeout.setPageNumber(0);
    strikeout.setPoints(points);
    strikeout.setReplies(replies);
    
    // Add annotation and save to file
    annotator.add(strikeout);
    annotator.save("outputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}

On this page