Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save groupdocs-cloud-gists/88823a8ad88ff612872dfb7b9129af8d to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/88823a8ad88ff612872dfb7b9129af8d to your computer and use it in GitHub Desktop.
How to Extract Text from PowerPoint PPT/PPTX in Node.js
// How to Extract All Text from PowerPoint PPT/PPTX in Node.js using REST API
const parse = async () => {
global.parseApi = groupdocs_parser_cloud.ParseApi.fromKeys(clientId, clientSecret);
let fileInfo = new groupdocs_parser_cloud.FileInfo();
fileInfo.filePath = "nodejs-testing/sample-file.pptx";
let options = new groupdocs_parser_cloud.TextOptions();
options.fileInfo = fileInfo;
let formattedTextOptions = new groupdocs_parser_cloud.FormattedTextOptions();
formattedTextOptions.mode = "PlainText";
options.formattedTextOptions = formattedTextOptions;
try {
// Create parse document request
let request = new groupdocs_parser_cloud.TextRequest(options);
let response = await parseApi.text(request);
// Display results
console.log(response.text);
}
catch (err) {
throw err;
}
}
parse()
.then(() => {
console.log("Successfully extracted text from PowerPoint PPTX document.");
})
.catch((err) => {
console.log("Error occurred while extracting text from PowerPoint PPTX file:", err);
})
// How to Extract Text from PowerPoint PPT by Page Number Range in Node.js
const parse = async () => {
global.parseApi = groupdocs_parser_cloud.ParseApi.fromKeys(clientId, clientSecret);
let fileInfo = new groupdocs_parser_cloud.FileInfo();
fileInfo.filePath = "nodejs-testing/sample-file.pptx";
let options = new groupdocs_parser_cloud.TextOptions();
options.fileInfo = fileInfo;
options.startPageNumber = 0;
options.countPagesToExtract = 2;
let formattedTextOptions = new groupdocs_parser_cloud.FormattedTextOptions();
formattedTextOptions.mode = "PlainText";
options.formattedTextOptions = formattedTextOptions;
try {
// Create parse document request
let request = new groupdocs_parser_cloud.TextRequest(options);
let response = await parseApi.text(request);
// Display results
let pages = response.pages;
pages.forEach(page => console.log("Page No: " + page.pageIndex + " - " + page.text));
}
catch (err) {
throw err;
}
}
parse()
.then(() => {
console.log("Successfully extracted text from PowerPoint Presentation.");
})
.catch((err) => {
console.log("Error occurred while extracting text from PowerPoint file:", err);
})

You can extract Text from PowerPoint programmatically on the cloud. In this article, we will learn how to extract Text from PowerPoint PPT/PPTX in Node.js.

The following topics are covered in this article:

  1. Node.js Library to Extract Text from PowerPoint PPT
  2. Extract All Text from PowerPoint PPT/PPTX in Node.js using REST API
  3. Extract Text from PowerPoint PPT by Page Number Range in Node.js
// open file in IOStream from your system drive.
var resourcesFolder = 'H:\\groupdocs-cloud-data\\sample-file.pptx';
// read file
fs.readFile(resourcesFolder, (err, fileStream) => {
// construct FileApi
var fileApi = groupdocs_parser_cloud.FileApi.fromConfig(config);
// create upload file request
var request = new groupdocs_parser_cloud.UploadFileRequest("sample-file.pptx", fileStream, myStorage);
// upload file
fileApi.uploadFile(request)
.then(function (response) {
console.log("Expected response type is FilesUploadResult: " + response.uploaded.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
});
# Import Node.js SDK in your node application from http://api.groupdocs.cloud
global.groupdocs_parser_cloud = require("groupdocs-parser-cloud");
global.fs = require("fs");
// get clientId and clientSecret from https://dashboard.groupdocs.cloud (free registration is required).
global.clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
global.clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
global.myStorage = "test-internal-storage";
const config = new groupdocs_parser_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment