Related blog post: Add or Remove Annotations in Word Documents in Java
Created
March 21, 2022 08:06
-
-
Save GroupDocsGists/e7fb039edd9b4a84b04b94ae117179dc to your computer and use it in GitHub Desktop.
Annotate Word files in Java - Add or Remove Annotations of DOC/DOCX files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Arrow annotation to Word documents in Java | |
final Annotator annotator = new Annotator("path/document.docx"); | |
ArrowAnnotation arrow = new ArrowAnnotation(); | |
arrow.setBox(new Rectangle(100, 100, 100, 100)); | |
arrow.setMessage("Arrow annotation"); | |
arrow.setOpacity(0.7); | |
arrow.setPageNumber(0); | |
arrow.setPenColor(0x65535); | |
arrow.setPenStyle(PenStyle.Dot); | |
arrow.setPenWidth((byte) 3); | |
annotator.add(arrow); | |
annotator.save("path/annotatedDoc.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Distance annotation to Word documents in Java | |
final Annotator annotator = new Annotator("path/document.docx"); | |
DistanceAnnotation distance = new DistanceAnnotation(); | |
distance.setBox(new Rectangle(200, 150, 200, 30)); | |
distance.setCreatedOn(Calendar.getInstance().getTime()); | |
distance.setMessage("This is distance annotation"); | |
distance.setOpacity(0.7); | |
distance.setPageNumber(0); | |
distance.setPenColor(65535); | |
distance.setPenStyle(PenStyle.Dot); | |
distance.setPenWidth((byte) 3); | |
distance.setReplies(replies); | |
annotator.add(distance); | |
annotator.save("path/annotatedDoc.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Oval or Ellipse Annotation in Word documents in Java | |
final Annotator annotator = new Annotator("path/document.docx"); | |
EllipseAnnotation ellipse = new EllipseAnnotation(); | |
ellipse.setBackgroundColor(65535); | |
ellipse.setBox(new Rectangle(100, 100, 100, 100)); | |
ellipse.setCreatedOn(Calendar.getInstance().getTime()); | |
ellipse.setMessage("This is ellipse annotation"); | |
ellipse.setOpacity(0.7); | |
ellipse.setPageNumber(0); | |
ellipse.setPenColor(65535); | |
ellipse.setPenStyle(PenStyle.Dot); | |
ellipse.setPenWidth((byte) 3); | |
ellipse.setReplies(replies); | |
annotator.add(ellipse); | |
annotator.save("path/annotatedDoc.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Area or Rectangle Annotation in Word documents in Java | |
final Annotator annotator = new Annotator("path/document.docx"); | |
AreaAnnotation area = new AreaAnnotation(); | |
area.setBackgroundColor(65535); | |
area.setBox(new Rectangle(100, 100, 100, 100)); | |
area.setCreatedOn(Calendar.getInstance().getTime()); | |
area.setMessage("This is area annotation"); | |
area.setOpacity(0.7); | |
area.setPageNumber(0); | |
area.setPenColor(65535); | |
area.setPenStyle(PenStyle.Dot); | |
area.setPenWidth((byte) 3); | |
area.setReplies(replies); | |
annotator.add(area); | |
annotator.save("path/annotatedDoc.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove all the annotations from the Word document in Java | |
final Annotator annotator = new Annotator("path/annotatedDoc.docx"); | |
SaveOptions saveOptions = new SaveOptions(); | |
saveOptions.setAnnotationTypes(AnnotationType.None); | |
annotator.save("path/annotationsRemoved.docx", saveOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment