Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active February 24, 2023 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/4ad657ed428f37121404cdf93b9aa0f5 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/4ad657ed428f37121404cdf93b9aa0f5 to your computer and use it in GitHub Desktop.
Highlight Text in PDF using REST API in Node.js
// This code example demonstrates how to add highlight annotations to PDF file.
// Initialize api instance
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);
// Define annotation
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
// Point 1
let p1 = new groupdocs_annotation_cloud.Point();
p1.x = 30;
p1.y = 710;
// Point 2
let p2 = new groupdocs_annotation_cloud.Point();
p2.x = 460;
p2.y = 710;
// Point 3
let p3 = new groupdocs_annotation_cloud.Point();
p3.x = 30;
p3.y = 690;
// Point 4
let p4 = new groupdocs_annotation_cloud.Point();
p4.x = 460;
p4.y = 690;
// Add points
a1.points = [p1, p2, p3, p4];
// Background color
a1.backgroundColor = 3329434;
// Type
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.TextHighlight;
// Input file
let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
// Define AnnotateOptions
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
// Assign annotation
options.annotations = [a1];
// Output file path
options.outputPath = "output.pdf";
// Create Annotate request
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// Annotate
let result = await annotateApi.annotate(request);
// Done
console.log("AddAreaAnnotation: Area Annotation added: " + result.href);
// This code example demonstrates how to add your client Id and Secret in the code.
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";
// This code example demostrates how to download a PDF file from the cloud.
// Construct FileApi
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);
// Create download file request
let request = new groupdocs_annotation_cloud.DownloadFileRequest("output.pdf", myStorage);
// Download file
let response = await fileApi.downloadFile(request);
// Save file in your working directory
fs.writeFile("C:\\Files\\Annotation\\output.pdf", response, "binary", function (err) { });
// This code example demonstrates how to upload a PDF file to the cloud.
// Initialize api instance
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);
// Open file in IOStream from local/disc.
var resourcesFolder = 'C:\\Files\\Annotation\\sample.pdf';
// Read the file
fs.readFile(resourcesFolder, (err, fileStream) => {
// Upload file request
var request = new groupdocs_annotation_cloud.UploadFileRequest("sample.pdf", 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