Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Created January 14, 2022 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/ca543f2dc432be94188e35eadcf9946f to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/ca543f2dc432be94188e35eadcf9946f to your computer and use it in GitHub Desktop.
Compare Two or More PowerPoint Presentations using a REST API in Node.js.

Learn how to compare two or more PowerPoint presentations using a REST API in Node.js:https://blog.groupdocs.cloud/2022/01/14/compare-powerpoint-presentations-in-node-js/

The following topics shall be covered in this article:

  1. REST API and Node.js SDK to Compare PPTX Files
  2. Compare Two PowerPoint Presentations using a REST API in Node.js
  3. Compare Multiple PowerPoint Files using Node.js
  4. Get List of Changes using REST API in Node.js
// This code example demonstrates how to compare multiple PPTX files
// Initialize api
let compareApi = groupdocs_comparison_cloud.CompareApi.fromKeys(clientId, clientSecret);
// Source file
let source = new groupdocs_comparison_cloud.FileInfo();
source.filePath = "source.pptx";
// Target file 1
let target1 = new groupdocs_comparison_cloud.FileInfo();
target1.filePath = "target.pptx";
// Target file 2
let target2 = new groupdocs_comparison_cloud.FileInfo();
target2.filePath = "target2.pptx";
// Define compare options
let options = new groupdocs_comparison_cloud.ComparisonOptions();
options.sourceFile = source;
options.targetFiles = [target1, target2];
options.outputPath = "result_Multiple.pptx";
// Create comparison request
let request = new groupdocs_comparison_cloud.ComparisonsRequest(options);
// Compare
let response = await compareApi.comparisons(request);
console.log("Output file link: " + response.href);
// This code example demonstrates how to compare two PPTX files
// Initialize api
let compareApi = groupdocs_comparison_cloud.CompareApi.fromKeys(clientId, clientSecret);
// Source file
let source = new groupdocs_comparison_cloud.FileInfo();
source.filePath = "source.pptx";
// Target file
let target = new groupdocs_comparison_cloud.FileInfo();
target.filePath = "target.pptx";
// Define compare settings
let settings = new groupdocs_comparison_cloud.Settings();
// Compare sensitivity
settings.sensitivityOfComparison = 100;
// Define compare options
let options = new groupdocs_comparison_cloud.ComparisonOptions();
options.sourceFile = source;
options.targetFiles = [target];
options.outputPath = "result.pptx";
options.settings = settings;
// Create comparison request
let request = new groupdocs_comparison_cloud.ComparisonsRequest(options);
// Compare
let response = await compareApi.comparisons(request);
console.log("Output file link: " + response.href);
// This code example demonstrates how to add Client ID and Secret in the code.
global.ClientId = "659fe7da-715b-4744-a0f7-cf469a392b73";
global.ClientSecret = "b377c36cfa28fa69960ebac6b6e36421";
global.myStorage = "";
const config = new groupdocs_comparison_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";
// This code example demonstrates how to download PPTX file from the cloud.
// Construct FileApi
let fileApi = groupdocs_comparison_cloud.FileApi.fromConfig(config);
// Create download file request
let request = new groupdocs_comparison_cloud.DownloadFileRequest("result.pptx", myStorage);
// Download file
let response = await fileApi.downloadFile(request);
// Save in the working directory
fs.writeFile("C:\\Files\\comparison\\result.pptx", response, "binary", function (err) { });
// This code example demonstrates how to get list of all the changes.
// Initialize api
let compareApi = groupdocs_comparison_cloud.CompareApi.fromKeys(clientId, clientSecret);
// Source file
let source = new groupdocs_comparison_cloud.FileInfo();
source.filePath = "source.pptx";
// Target file
let target = new groupdocs_comparison_cloud.FileInfo();
target.filePath = "target.pptx";
// Define compare options
let options = new groupdocs_comparison_cloud.ComparisonOptions();
options.sourceFile = source;
options.targetFiles = [target];
options.outputPath = "result.pptx";
// Create comparison request
let request = new groupdocs_comparison_cloud.PostChangesRequest(options);
let changes = await compareApi.postChanges(request);
// Show results
console.log("Changes count: " + changes.length);
changes.forEach(change => {
console.log(change.id + 1 +"- Target Text: " + change.targetText + ", Text: " + change.text + ", Type: " + change.type);
});
// This code example demonstrates how to upload multiple files to the cloud.
// Construct FileApi
let fileApi = groupdocs_comparison_cloud.FileApi.fromConfig(config);
let resourcesFolder = 'C:\\Files\\comparison\\upload\\';
fs.readdir(resourcesFolder, (err, files) => {
files.forEach(file => {
// Read file
fs.readFile(resourcesFolder + file, (err, fileStream) => {
// Upload file request
let request = new groupdocs_comparison_cloud.UploadFileRequest(file, 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