Last active
July 15, 2021 06:32
-
-
Save groupdocs-cloud-gists/b8df495569125131c0bf0577097bc96f to your computer and use it in GitHub Desktop.
Parse Word Documents using a REST API in Node.js
This file contains 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
Parse Word Documents using a REST API in Node.js | |
1. Parse Word Documents and Extract Images | |
2. Parse Word Documents and Extract Text |
This file contains 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 = "112f0f38-9dae-42d5-b4fc-cc84ae644972"; | |
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618"; | |
global.myStorage = ""; | |
const configuration = new groupdocs_parser_cloud.Configuration(clientId, clientSecret); | |
configuration.apiBaseUrl = "https://api.groupdocs.cloud"; |
This file contains 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 | |
var fileApi = groupdocs_parser_cloud.FileApi.fromConfig(configuration); | |
// create file download request | |
let request = new groupdocs_parser_cloud.DownloadFileRequest("parser/images/sample_docx/image_0.png", myStorage); | |
// download file | |
let response = await fileApi.downloadFile(request); | |
// save image file in working directory | |
fs.writeFile("C:\\Files\\images\\image_0.png", response, "binary", function (err) { }); | |
console.log(response); |
This file contains 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 parseApi = groupdocs_parser_cloud.ParseApi.fromConfig(configuration); | |
// sample file info | |
let fileInfo = new groupdocs_parser_cloud.FileInfo(); | |
fileInfo.filePath = "sample.docx"; | |
// define image options | |
let options = new groupdocs_parser_cloud.ImagesOptions(); | |
options.fileInfo = fileInfo; | |
// create image request | |
let request = new groupdocs_parser_cloud.ImagesRequest(options); | |
// get images | |
let result = await parseApi.images(request); | |
// show images download path | |
let images = result.images; | |
images.forEach(image => { | |
console.log("Image path in storage: " + image.path); | |
console.log("Download url: " + image.downloadUrl); | |
console.log("Image format: " + image.fileFormat + ". Page index: " + image.pageIndex); | |
}); |
This file contains 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 parseApi = groupdocs_parser_cloud.ParseApi.fromConfig(configuration); | |
// sample file info | |
let fileInfo = new groupdocs_parser_cloud.FileInfo(); | |
fileInfo.filePath = "sample.docx"; | |
// define text options | |
let options = new groupdocs_parser_cloud.TextOptions(); | |
options.fileInfo = fileInfo; | |
options.startPageNumber = 0; | |
options.countPagesToExtract = 1; | |
options.formattedTextOptions = new groupdocs_parser_cloud.FormattedTextOptions({ | |
mode: "Html" // extract text in HTML | |
}); | |
// create text request | |
let request = new groupdocs_parser_cloud.TextRequest(options); | |
// get text | |
let result = await parseApi.text(request); | |
// show extracted text | |
let pages = result.pages; | |
pages.forEach(page => console.log(page.text)); |
This file contains 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 fileApi = groupdocs_parser_cloud.FileApi.fromConfig(configuration); | |
let resourcesFolder = 'C:\\Files\\sample.docx'; | |
// read file | |
fs.readFile(resourcesFolder, (err, fileStream) => { | |
// create file upload request | |
let request = new groupdocs_parser_cloud.UploadFileRequest("sample.docx", 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