How To Annotate PDF in Node.js Using GroupDocs.Annotation REST API

Hi,
We are trying to evaluate groupdocs annotation functionality for our project. I am using nodejs sdk and following the samples provided in github.

Repo URL - GitHub - groupdocs-annotation-cloud/groupdocs-annotation-cloud-node-samples: GroupDocs.Annotation Cloud SDK for Node.js examples, plugins and showcase projects

I am calling “Annotation_Node_Add_Area_Annotation” and getting success response from API. Here is the response - Expected response type is void: Area Annotation added.

But I did not find any annotation done in PDF (ten-pages.pdf) stored in groupdocs cloud. Am I Missing anything?

Thanks,
Neeraj

@giga.neeraj

Please note, there are two steps, first annotate the document and then retrieve the annotated document. You have annotated the PDF document, please check following example to get annotated PDF document result from cloud storage. Hopefully it will help you to accomplish the task.

GET annotation/result

@giga.neeraj

As an update, we have removed GetExport API method in GroupDocs.Annotation Cloud 21.2 release. Now you can annotate PDF in Node.js using GroupDocs.Annotation REST API and use DownloadFile API method to download the file as following.

PDF Markup in Node.js

// For complete examples and data files, please go to https://github.com/groupdocs-annotation-cloud/groupdocs-annotation-cloud-node-samples
annotation_cloud = require("groupdocs-annotation-cloud");
var fs = require('fs');
 
const annotatePDF = async () => {
const appSid = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
const appKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
  
annotateApi = annotation_cloud.AnnotateApi.fromKeys(appSid, appKey);
fileApi = annotation_cloud.FileApi.fromKeys(appSid, appKey);
 
let a1 = new annotation_cloud.AnnotationInfo();
a1.annotationPosition = new annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new 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 = annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a1.penWidth = 1;
a1.type = annotation_cloud.AnnotationInfo.TypeEnum.Area;
a1.text = "This is area annotation";
a1.creatorName = "Anonym A.";
 
let fileInfo = new annotation_cloud.FileInfo();
fileInfo.filePath = "02_pages.pdf";
let options = new annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1];
options.outputPath = "annotateoutput.pdf";
let result = await annotateApi.annotate(new annotation_cloud.AnnotateRequest(options));

//Downlaod PDF document from cloud stroage
const localPath = "C:/Temp/annotateoutput.pdf";
let downloadResult = await fileApi.downloadFile(new annotation_cloud.DownloadFileRequest("annotateoutput.pdf"));
fs.writeFileSync(localPath,downloadResult);
 

}

annotatePDF()
.then(() => {
console.log("PDF document annotated successfully");
})
.catch((err) => {
console.log("Error occurred while annotated the PDF document:", err);
})