Last active
August 14, 2021 09:10
-
-
Save groupdocs-cloud-gists/3996a16f459608497377aa2afcfc9ebe to your computer and use it in GitHub Desktop.
Extract or Remove Annotations from PDF using a REST API in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can easily extract or remove all the annotations from documents using a REST API in Node.js. | |
Please follow the steps mentioned below: | |
1. Upload the PDF file to the Cloud | |
2. Extract Annotations from PDF Files in Node.js | |
3. Remove Annotations from PDF Files in Node.js | |
4. Download the updated file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// construct FileApi | |
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration); | |
// create download file request | |
let request = new groupdocs_annotation_cloud.DownloadFileRequest("Output/output.pdf", myStorage); | |
let response = await fileApi.downloadFile(request); | |
// save file in working directory | |
fs.writeFile("C:\\Files\\output.pdf", response, "binary", function (err) { }); | |
console.log(response); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret); | |
// input file | |
let fileInfo = new groupdocs_annotation_cloud.FileInfo(); | |
fileInfo.filePath = "sample.pdf"; | |
// create extract request | |
let request = new groupdocs_annotation_cloud.ExtractRequest(fileInfo); | |
// extract | |
let result = await annotateApi.extract(request); | |
// show results | |
console.log("GetAnnotations: annotations count = " + result.length); | |
result.forEach(element => console.log("Annotation ID:" + element.id + " Element Text: " + element.text)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret); | |
// input file path | |
let fileInfo = new groupdocs_annotation_cloud.FileInfo(); | |
fileInfo.filePath = "sample.pdf"; | |
// define remove options | |
let options = new groupdocs_annotation_cloud.RemoveOptions(); | |
options.fileInfo = fileInfo; | |
options.annotationIds = [0, 1, 2, 3]; | |
options.outputPath = "Output/output.pdf"; | |
// create remove annotation request | |
let request = new groupdocs_annotation_cloud.RemoveAnnotationsRequest(options); | |
// Remove annotations | |
let result = await annotateApi.removeAnnotations(request); | |
console.log("DeleteAnnotations: annotations delete: " + result.href); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration); | |
// input file | |
var resourcesFolder = 'C:\\Files\\sample.pdf'; | |
// read file | |
fs.readFile(resourcesFolder, (err, fileStream) => { | |
// create 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