We can easily annotate Word documents programmatically on the cloud. We can add images, comments, notes, or other types of external remarks to the documents as annotations. In this article, we will learn how to add annotations in Word documents using a REST API in Node.js.
The following topics shall be covered in this article:
- Word Document Annotation REST API and Node.js SDK
- Annotate Word Documents using REST API in Node.js
- Add Image Annotations in Word Documents using REST API in Node.js
- Add Text Field Annotations in Word Documents using REST API Node.js
- Watermark Annotations in Word Documents using REST API in Node.js
Word Document Annotation REST API and Node.js SDK
For annotating DOC or DOCX files, we will be using the Node.js SDK of GroupDocs.Annotation Cloud API. Please install it using the following command in the console:
npm install groupdocs-annotation-cloud
Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:
Annotate Word Documents using REST API in Node.js
We can add annotations to the DOCX files by following the simple steps mentioned below:
- Upload the DOCX file to the Cloud
- Add Multiple Annotations to DOCX Files in Node.js
- Download the annotated file
Upload the Document
Firstly, we will upload the DOCX file to the Cloud using the code example given below:
As a result, the uploaded DOCX file will be available in the files section of the dashboard on the cloud.
Add Multiple Annotations to DOCX Files in Node.js
We can add multiple annotations to the Word documents programmatically by following the steps given below:
- Firstly, create an instance of the AnnotateApi.
- Next, create the first instance of the AnnotationInfo.
- Then, set annotation properties for the first instance e.g., position, type, text, etc.
- Repeat above steps to add multiple instances of the AnnotationInfo. We will set different annotation types and other properties for each instance to add multiple annotations.
- Next, create an instance of the FileInfo and set the input file path.
- Then, create an instance of the AnnotateOptions.
- Now, assign the FileInfo and defined annotation instances to the AnnotateOptions.
- Also, set the output file path.
- After that, call the AnnotateRequest method with AnnotateOptions.
- Finally, get results by calling the AnnotateApi.annotate() method with AnnotateRequest.
The following code sample shows how to add multiple annotations to a Word document using a REST API in Node.js.
Download the Annotated File
The above code sample will save the annotated Word document (DOCX) on the cloud. It can be downloaded using the following code sample:
Add Image Annotations in Word Documents using REST API in Node.js
We can add image annotations in Word documents programmatically by following the steps given below:
- Firstly, create an instance of the AnnotateApi.
- Next, create an instance of the AnnotationInfo.
- Then, define a rectangle and set its position, height, and width.
- After that, set annotation properties e.g., position, text, height, width, etc.
- Then, set the annotation type as Image.
- Next, create an instance of the FileInfo and set the input file path.
- Then, create an instance of the AnnotateOptions.
- Now, assign the FileInfo object and annotation to the AnnotateOptions.
- Also, set the output file path.
- After that, create a request by calling the AnnotateRequest method with AnnotateOptions object as argument.
- Finally, get results by calling the AnnotateApi.annotate() method with AnnotateRequest object.
The following code sample shows how to add an image annotation to a Word document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.
Add Text Field Annotations in Word Documents using REST API in Node.js
We can add text field annotations in Word documents programmatically by following the steps mentioned earlier. However, we need to set the annotation type as TextField.
The following code sample shows how to add a text field annotation to a Word document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.
Watermark Annotations in Word Documents using REST API in Node.js
We can add watermark annotations in Word documents programmatically by following the steps mentioned earlier. However, we need to set the annotation type as Watermark.
The following code sample shows how to add watermark annotation to a Word document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.
Try Online
Please try the following free online DOCX annotation tool, which is developed using the above API. https://products.groupdocs.app/annotation/docx
Conclusion
In this article, we have learned how to add annotations to Word documents on the cloud. We have also seen how to add image and text field annotations to the DOCX file using a REST API in Node.js. This article also explained how to programmatically upload a DOCX file to the cloud and then download the edited file from the Cloud. Besides, you can learn more about GroupDocs.Annotation Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.