Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save groupdocs-cloud-gists/51dc04f5862574a11a6c514a55818e1c to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/51dc04f5862574a11a6c514a55818e1c to your computer and use it in GitHub Desktop.
Merge Multiple PowerPoint Presentations into One in Node.js
// Import Node.js SDK in your node application from http://api.groupdocs.cloud
global.groupdocs_merger_cloud = require("groupdocs-merger-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_merger_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";
// How to merge specific slides of ppt/pptx files using Node.js
const mergespecific = async () => {
// Merge ppt/pptx api initialization
let documentApi = groupdocs_merger_cloud.DocumentApi.fromKeys(clientId, clientSecret);
// create first join item
let item1 = new groupdocs_merger_cloud.JoinItem();
item1.fileInfo = new groupdocs_merger_cloud.FileInfo();
item1.fileInfo.filePath = "nodejs-testing/sample-file1.pptx";
item1.pages = [3, 4];
// create second join item
let item2 = new groupdocs_merger_cloud.JoinItem();
item2.fileInfo = new groupdocs_merger_cloud.FileInfo();
item2.fileInfo.filePath = "nodejs-testing/sample-file2.pptx";
item2.startPageNumber = 2
item2.endPageNumber = 4
// create join options
let options = new groupdocs_merger_cloud.JoinOptions();
options.joinItems = [item1, item2];
options.outputPath = "nodejs-testing/joined-file.pptx";
try {
// Create join documents request
let joinRequest = new groupdocs_merger_cloud.JoinRequest(options);
let result = await documentApi.join(joinRequest);
}
catch (err) {
throw err;
}
}
mergespecific()
.then(() => {
console.log("Successfully merged pptx slides: ");
})
.catch((err) => {
console.log("Error occurred while combining the PowerPoint files:", err);
})

You can combine multiple PowerPoint Presentations into single file programmatically on the cloud. In this article, you will learn how to combine PowerPoint Presentations into One in Node.js.

The following topics shall be covered in this article:

  1. Document Merger REST API and Node.js SDK
  2. Merge Multiple PowerPoint Presentations in Node.js using REST API
  3. How to Merge Specific PowerPoint Slides using Node.js
  4. Upload and Download PowerPoint Presentations
// How to combine PowerPoint ppt/pptx files using Node.js
const combine = async () => {
let documentApi = groupdocs_merger_cloud.DocumentApi.fromKeys(clientId, clientSecret);
// create first join item
let item1 = new groupdocs_merger_cloud.JoinItem();
item1.fileInfo = new groupdocs_merger_cloud.FileInfo();
item1.fileInfo.filePath = "nodejs-testing/sample-file1.pptx";
// create second join item
let item2 = new groupdocs_merger_cloud.JoinItem();
item2.fileInfo = new groupdocs_merger_cloud.FileInfo();
item2.fileInfo.filePath = "nodejs-testing/sample-file2.pptx";
// create join options
let options = new groupdocs_merger_cloud.JoinOptions();
options.joinItems = [item1, item2];
options.outputPath = "nodejs-testing/joined-file.pptx";
try {
// Create join documents request
let joinRequest = new groupdocs_merger_cloud.JoinRequest(options);
let result = await documentApi.join(joinRequest);
}
catch (err) {
throw err;
}
}
combine()
.then(() => {
console.log("Successfully combined powerpoint pptx files: ");
})
.catch((err) => {
console.log("Error occurred while merging the PowerPoint files:", err);
})
// construct FileApi to download merged file
var fileApi = groupdocs_merger_cloud.FileApi.fromConfig(config);
// create donwload file request
let request = new groupdocs_merger_cloud.DownloadFileRequest("nodejs-testing/joined-file.pptx", myStorage);
// download file and response type Stream
fileApi.downloadFile(request)
.then(function (response) {
// save file in your system directory
fs.writeFile("H:\\groupdocs-cloud-data\\joined-file.pptx", response, "binary", function (err) { });
console.log("Expected response type is Stream: " + response.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
// construct FileApi
let fileApi = groupdocs_merger_cloud.FileApi.fromConfig(config);
// open multiple pptx files folder from your system drive.
let resourcesFolder = 'H:\\groupdocs-cloud-data\\sample-pptx\\';
fs.readdir(resourcesFolder, (err, files) => {
files.forEach(file => {
// read files one by one
fs.readFile(resourcesFolder + file, (err, fileStream) => {
// create upload file request
let request = new groupdocs_merger_cloud.UploadFileRequest("nodejs-testing/" + file, fileStream, myStorage);
// upload file
fileApi.uploadFile(request)
.then(function (response) {
console.log(file + " file uploaded: " + response.uploaded.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment