Extract or Remove Annotations from PDF using REST API in Node.js

Annotations are comments, popups, and various other graphical objects in the document providing additional information. You can easily add various types of annotations to your documents programmatically on the cloud. You can also extract or remove all the annotations from documents using Node.js. In this article, you will learn how to extract or remove annotations from PDF documents using a REST API in Node.js.

The following topics shall be covered in this article:

Document Annotation REST API and Node.js SDK

I will be using the Node.js SDK of GroupDocs.Annotation Cloud API for extracting or removing the annotations from PDF documents. It allows you to build document annotator tools in Node.js. Such tools can be used to add, edit, or delete annotations, watermark overlays, text replacements, redactions, sticky notes, and text markups to all popular document formats such as PDF, Word, Excel, PowerPoint, Outlook, and image formats. It also provides .NET, Java, PHP, Ruby, and Python SDKs as its document annotation family members for the Cloud API.

You can install GroupDocs.Annotation Cloud to your Node.js application using the following command in the console:

npm install groupdocs-annotation-cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as shown below:

Extract or Remove Annotations from PDF Files using a REST API in Node.js

You can extract or delete all the annotations from the PDF documents by following the simple steps mentioned below:

Upload the Document

Firstly, upload the PDF file to the Cloud using the code example given below:

As a result, the uploaded PDF file will be available in the files section of your dashboard on the cloud.

Extract Annotations from PDF Files in Node.js

You can extract all the annotations from PDF documents programmatically by following the steps mentioned below:

  • Create an instance of the AnnotateApi
  • Create an instance of the FileInfo
  • Set the input file path
  • Create a request by calling the ExtractRequest method with FileInfo object
  • Get results by calling the AnnotateApi.extract() method with ExtractRequest object

The following code snippet shows how to extract annotations from the PDF document using a REST API in Node.js.

Extract Annotations from PDF Files in Node.js

Extract Annotations from PDF Files in Node.js

Remove Annotations from PDF Documents in Node.js

You can delete the annotations from PDF documents programmatically by following the steps mentioned below:

  • Create an instance of the AnnotateApi
  • Create an instance of the FileInfo
  • Set the input file path
  • Create an instance of the RemoveOptions
  • Set the FileInfo to RemoveOptions
  • Provide annotation IDs to remove
  • Set the output file path
  • Create a request by calling the RemoveAnnotationsRequest method with RemoveOptions object
  • Get results by calling the AnnotateApi.removeAnnotations() method

The following code example shows how to remove annotations from the PDF document using a REST API in Node.js. You can get annotation IDs using the extract() method with ExtractRequest as described earlier.

Remove Annotations from PDF Documents in Node.js

Remove Annotations from PDF Documents in Node.js

Download the Output File

The above code sample will save the output file after removing annotations on the cloud. You can download it using the following code sample:

Try Online

Please try the following free online PDF annotation tool, which is developed using the above API. https://products.groupdocs.app/annotation/pdf

Conclusion

In this article, you have learned how to extract or remove annotations from PDF documents on the cloud using Node.js. You have also learned how to programmatically upload the PDF file on the cloud and then download the updated file from the cloud. You can learn even 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.

See Also