Created
June 24, 2021 05:23
-
-
Save GroupDocsGists/8b7eabe47e6268c246f47e8fb58529f5 to your computer and use it in GitHub Desktop.
Annotate Word files using C# - 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 multiple annotations to Word using C# | |
// Adding Arrow, Area, Oval (Ellipse), Distance annotations to DOC/DOCX with messages and replies using C# | |
string outputPath = @"outputPath/annotatedDoc.docx"; | |
string inputFile = @"inputPath/document.docx"; | |
using (Annotator annotator = new Annotator(inputFile)) | |
{ | |
ArrowAnnotation arrow = new ArrowAnnotation | |
{ | |
Box = new Rectangle(550, 250, 60, -60), | |
CreatedOn = DateTime.Now, | |
Message = "This image is little upwards.", | |
Opacity = 0.7, | |
PageNumber = 0, | |
PenColor = -3407872, | |
PenStyle = PenStyle.Solid, | |
PenWidth = 2, | |
Replies = new List<Reply> | |
{ | |
new Reply | |
{ | |
Comment = "Please look in to these issues.", | |
RepliedOn = DateTime.Now | |
}, | |
new Reply | |
{ | |
Comment = "Change Description", | |
RepliedOn = DateTime.Now | |
}, | |
new Reply | |
{ | |
Comment = "On-Premises APIs", | |
RepliedOn = DateTime.Now | |
}, | |
new Reply | |
{ | |
Comment = "Add images as well.", | |
RepliedOn = DateTime.Now | |
} | |
} | |
}; | |
AreaAnnotation area = new AreaAnnotation | |
{ | |
BackgroundColor = 65535, | |
Box = new Rectangle(80, 75, 450, 135), | |
Message = "This is area annotation", | |
Opacity = 0.2, | |
PageNumber = 0, | |
PenColor = -131, | |
PenStyle = PenStyle.Dash, | |
PenWidth = 3 | |
}; | |
EllipseAnnotation ellipse = new EllipseAnnotation | |
{ | |
BackgroundColor = -16034924, | |
Box = new Rectangle(275, 475, 300, 80), | |
Message = "This is ellipse annotation", | |
Opacity = 0.2, | |
PageNumber = 0, | |
PenColor = -16034924, | |
PenStyle = PenStyle.Dot, | |
PenWidth = 3 | |
}; | |
DistanceAnnotation distance = new DistanceAnnotation | |
{ | |
Box = new Rectangle(750, 235, 0, 150), | |
Message = "This is the heading area", | |
Opacity = 0.7, | |
PageNumber = 0, | |
PenColor = -21197, | |
PenStyle = PenStyle.Solid, | |
PenWidth = 3 | |
}; | |
annotator.Add(arrow); | |
annotator.Add(area); | |
annotator.Add(ellipse); | |
annotator.Add(distance); | |
annotator.Save(outputPath); | |
} |
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 using C# | |
using (Annotator annotator = new Annotator("path/document.docx")) | |
{ | |
ArrowAnnotation arrow = new ArrowAnnotation | |
{ | |
Box = new Rectangle(100, 100, 50, 50), | |
CreatedOn = DateTime.Now, | |
Message = "Your Message", | |
Opacity = 0.7, | |
PageNumber = 0, | |
PenColor = -3407872, | |
PenStyle = PenStyle.Solid, | |
PenWidth = 2 | |
}; | |
annotator.Add(arrow); | |
annotator.Save("path/annotation.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 using C# | |
using (Annotator annotator = new Annotator("path/document.docx")) | |
{ | |
DistanceAnnotation distance = new DistanceAnnotation | |
{ | |
Box = new Rectangle(750, 235, 0, 150), | |
Message = "This is the heading area", | |
Opacity = 0.7, | |
PageNumber = 0, | |
PenColor = -21197, | |
PenStyle = PenStyle.Solid, | |
PenWidth = 3 | |
}; | |
annotator.Add(distance); | |
annotator.Save("path/annotation.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 using C# | |
using (Annotator annotator = new Annotator("path/document.docx")) | |
{ | |
EllipseAnnotation ellipse = new EllipseAnnotation | |
{ | |
BackgroundColor = -16034924, | |
Box = new Rectangle(275, 475, 300, 80), | |
Message = "This is ellipse annotation", | |
Opacity = 0.2, | |
PageNumber = 0, | |
PenColor = -16034924, | |
PenStyle = PenStyle.Dot, | |
PenWidth = 3 | |
}; | |
annotator.Add(ellipse); | |
annotator.Save("path/annotation.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 using C# | |
using (Annotator annotator = new Annotator("path/document.docx")) | |
{ | |
AreaAnnotation area = new AreaAnnotation | |
{ | |
BackgroundColor = 65535, | |
Box = new Rectangle(80, 75, 450, 135), | |
Message = "This is area annotation", | |
Opacity = 0.2, | |
PageNumber = 0, | |
PenColor = -131, | |
PenStyle = PenStyle.Dash, | |
PenWidth = 3 | |
}; | |
annotator.Add(area); | |
annotator.Save("path/annotation.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 using C# | |
using (Annotator annotator = new Annotator(outputPath)) | |
{ | |
annotator.Save(remOutputPath, new SaveOptions {AnnotationTypes = AnnotationType.None}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment