In certain cases, we may need to highlight a text phrase, line, or area in PDF documents. It helps to highlight important text with semitransparent color in an electronic format, the same way we do with a marker on standard paper. We can use the highlight feature programmatically using the highlight annotations within applications. In this article, we will learn how to highlight text in PDF using REST API in Node.js.
The following topics shall be covered in this article:
PDF Text Highlighter REST API and Node.js SDK
For highlighting the text in PDF files, we will be using the Node.js SDK of GroupDocs.Annotation Cloud API. It allows adding annotations, watermark overlays, text replacements, redactions, and text markups to the supported document formats. 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:
Highlight Text in PDF using REST API in Node.js
We can highlight text in PDF files by following the simple steps given below:
Upload the Document
Firstly, we will upload the PDF file to the cloud using the code sample given below:
As a result, the uploaded PDF file will be available in the files section of the dashboard on the cloud.
Highlight Text in PDF Document using Node.js
Now, we will add highlight annotations to highlight the text in the uploaded PDF document by following the steps given below:
- Firstly, create an instance of the AnnotateApi.
- Next, set annotation points positions.
- Then, assign points to AnnotationInfo object and set its background color and type.
- Next, provide the input file path.
- Then, initialize the AnnotateOptions object and set the output file path.
- After that, create the AnnotateRequest with AnnotateOptions as argument.
- Finally, highlight the text in PDF using the AnnotateApi.annotate() method.
The following code sample shows how to highlight text in a PDF document using a REST API in Node.js.
You can get the required color value from the following link to use as a background color. https://docs.microsoft.com/en-us/office/vba/api/excel.xlrgbcolor
Download the Annotated File
The above code sample will save the annotated PDF file on the cloud. It can be downloaded using the following code sample:
Please try the following free online PDF annotation tool, which is developed using the above API. https://products.groupdocs.app/annotation/pdf
In this article, we have learned how to:
- add highlight annotations to a PDF using Node.js;
- programmatically upload the PDF file to the cloud;
- download the annotated PDF 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.