Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Annotations in Word Documents using a REST API in Node.js
// Initialize API
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);
// Define image annotation
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
a1.annotationPosition = new groupdocs_annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new groupdocs_annotation_cloud.Rectangle();
a1.box.x = 300;
a1.box.y = 320;
a1.box.width = 200;
a1.box.height = 40;
a1.pageNumber = 0;
a1.penColor = 1201033;
a1.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a1.penWidth = 1;
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Image;
a1.text = "This is image annotation";
a1.creatorName = "Anonym A.";
a1.imagePath = "JohnSmith.png";
// Input file path
let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.docx";
// Define Annotation options
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1];
options.outputPath = "AddImageAnnotation.docx";
// Create annotate request
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// Annotate
let result = await annotateApi.annotate(request);
// Initialize API
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);
// Define Distance annotation
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
a1.annotationPosition = new groupdocs_annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new groupdocs_annotation_cloud.Rectangle();
a1.box.x = 100
a1.box.y = 100
a1.box.width = 200
a1.box.height = 100
a1.pageNumber = 0
a1.penColor = 1201033
a1.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a1.penWidth = 3
a1.opacity = 1
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Distance;
a1.text = "This is distance annotation";
a1.creatorName = "Anonym A.";
// Define Area annotation
let a2 = new groupdocs_annotation_cloud.AnnotationInfo();
a2.annotationPosition = new groupdocs_annotation_cloud.Point();
a2.annotationPosition.x = 1;
a2.annotationPosition.y = 1;
a2.box = new groupdocs_annotation_cloud.Rectangle();
a2.box.x = 80
a2.box.y = 400
a2.box.width = 200
a2.box.height = 100
a2.penColor = 1201033;
a2.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a2.pageNumber = 0;
a2.penWidth = 3;
a2.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Area;
a2.text = "This is area annotation";
a2.creatorName = "Anonym A.";
// Define Arrow annotation
let a3 = new groupdocs_annotation_cloud.AnnotationInfo();
a3.annotationPosition = new groupdocs_annotation_cloud.Point();
a3.annotationPosition.x = 1;
a3.annotationPosition.y = 1;
a3.box = new groupdocs_annotation_cloud.Rectangle();
a3.box.x = 100;
a3.box.y = 100;
a3.box.width = 200;
a3.box.height = 100;
a3.pageNumber = 0;
a3.penColor = 1201033;
a3.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a3.penWidth = 1;
a3.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Arrow;
a3.text = "This is arrow annotation";
a3.creatorName = "Anonym A.";
// Define Ellipse annotation
let a4 = new groupdocs_annotation_cloud.AnnotationInfo();
a4.annotationPosition = new groupdocs_annotation_cloud.Point();
a4.annotationPosition.x = 1;
a4.annotationPosition.y = 1;
a4.box = new groupdocs_annotation_cloud.Rectangle();
a4.box.x = 350;
a4.box.y = 350;
a4.box.width = 200;
a4.box.height = 100;
a4.pageNumber = 0;
a4.penColor = 1201033;
a4.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a4.penWidth = 4;
a4.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Ellipse;
a4.text = "This is ellipse annotation";
a4.creatorName = "Anonym A.";
// Input file path
let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.docx";
// Define annotate options
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1, a2, a3, a4];
options.outputPath = "AddMultipleAnnotations.docx";
// Create annotate request
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// Annotate
let result = await annotateApi.annotate(request);
// Initialize API
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);
// Define text field annotation
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
a1.annotationPosition = new groupdocs_annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new groupdocs_annotation_cloud.Rectangle();
a1.box.x = 300;
a1.box.y = 310;
a1.box.width = 200;
a1.box.height = 50;
a1.pageNumber = 0;
a1.fontColor = 3093151;
a1.fontSize = 12;
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.TextField;
a1.text = "Text field text";
a1.creatorName = "Anonym A.";
// Input file path
let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.docx";
// Define Annotation options
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1];
options.outputPath = "AddTextFieldAnnotation.docx";
// Create annotate request
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// Annotate
let result = await annotateApi.annotate(request);
// Initialize API
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);
// Define watermark annotation
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
a1.annotationPosition = new groupdocs_annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new groupdocs_annotation_cloud.Rectangle();
a1.box.x = 100;
a1.box.y = 700;
a1.box.width = 500;
a1.box.height = 100;
a1.pageNumber = 0;
a1.penColor = 1201033;
a1.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a1.penWidth = 2;
a1.fontSize = 24;
a1.angle = 75;
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Watermark;
a1.text = "This is a watermark annotation";
a1.creatorName = "Anonym A.";
// Input file path
let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.docx";
// Define Annotation options
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1];
options.outputPath = "AddWatermarkAnnotation.docx";
// Create annotate request
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// Annotate
let result = await annotateApi.annotate(request);
global.clientId = "659fe7da-715b-4744-a0f7-cf469a392b73";
global.clientSecret = "b377c36cfa28fa69960ebac6b6e36421";
global.myStorage = "";
const configuration = new groupdocs_annotation_cloud.Configuration(clientId, clientSecret);
configuration.apiBaseUrl = "https://api.groupdocs.cloud";
// Construct FileApi
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);
// Create download file request
let request = new groupdocs_annotation_cloud.DownloadFileRequest("AddMultipleAnnotations.docx", myStorage);
// Download file
let response = await fileApi.downloadFile(request);
// Save file in working directory
fs.writeFile("C:\\Files\\Annotation\\AddMultipleAnnotations.docx", response, "binary", function (err) { });
// Initialize API
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);
// Open file in IOStream from local/disc.
var resourcesFolder = 'C:\\Files\\Annotation\\sample.docx';
fs.readFile(resourcesFolder, (err, fileStream) => {
// Create upload request
var request = new groupdocs_annotation_cloud.UploadFileRequest("sample.docx", fileStream, myStorage);
// Upload file
fileApi.uploadFile(request);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment