Skip to content

Instantly share code, notes, and snippets.

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/cc004566f559eb08a31df7110e837992 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/cc004566f559eb08a31df7110e837992 to your computer and use it in GitHub Desktop.
Convert PowerPoint to JPG and JPG to PowerPoint in Node.js
// How to convert JPG file to PowerPoint PPTX in Node.js using Advanced Options
const convert_options = async () => {
const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
const settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.storageName = myStorage;
settings.filePath = "nodejs-testing/sample-jpg-file.jpg";
settings.format = "pptx";
var convertOptions = new groupdocs_conversion_cloud.PptxConvertOptions();
convertOptions.fromPage = 1;
convertOptions.pagesCount = 1;
convertOptions.zoom = 1;
settings.convertOptions = convertOptions;
settings.outputPath = "nodejs-testing/output-sample-file.pptx";
try {
// Create convert document request
const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
}
catch (err) {
throw err;
}
}
convert_options()
.then(() => {
console.log("Converted JPG file into PPTX file using advanced options.");
})
.catch((err) => {
console.log("Error occurred while converting the JPG file:", err);
})
// How to convert JPG File into PowerPoint Presentation in Node.js
const convert = async () => {
const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
const settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.storageName = myStorage;
settings.filePath = "nodejs-testing/sample-jpg-file.jpg";
settings.format = "pptx";
settings.outputPath = "nodejs-testing/output-sample-file.pptx";
try {
// Create convert document request
const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
}
catch (err) {
throw err;
}
}
//
convert()
.then(() => {
console.log("Successfully converted JPG to PPTX file format.");
})
.catch((err) => {
console.log("Error occurred while converting the JPG file:", err);
})
// How to Convert PPTX to JPG online using REST API in Node.js
const convert = async () => {
const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
const settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.storageName = myStorage;
settings.filePath = "nodejs-testing/sample-pptx-file.pptx";
settings.format = "jpg";
settings.outputPath = "nodejs-testing/output-sample-file.jpg";
try {
// Create convert document request
const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
}
catch (err) {
throw err;
}
}
convert()
.then(() => {
console.log("Successfully converted PowerPoint to JPG file format.");
})
.catch((err) => {
console.log("Error occurred while converting the PowerPoint file:", err);
})
// How to Convert PowerPoint Slide to JPG in Node.js using Advanced Options
const convert_options = async () => {
const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
const settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.storageName = myStorage;
settings.filePath = "nodejs-testing/sample-pptx-file.pptx";
settings.format = "jpg";
convertOptions = new groupdocs_conversion_cloud.JpgConvertOptions()
convertOptions.grayscale = true;
convertOptions.fromPage = 1;
convertOptions.pagesCount = 1;
convertOptions.quality = 100;
convertOptions.rotateAngle = 90;
convertOptions.usePdf = false;
settings.convertOptions = convertOptions;
settings.outputPath = "nodejs-testing/output-sample-file.jpg";
try {
// Create convert document request
const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
}
catch (err) {
throw err;
}
}
convert_options()
.then(() => {
console.log("Converted PPT to JPG image with advanced options.");
})
.catch((err) => {
console.log("Error occurred while converting the PPT file:", err);
})
// open file in IOStream from your system drive.
var resourcesFolder = 'H:\\groupdocs-cloud-data\\sample-pptx-file';
// read file
fs.readFile(resourcesFolder, (err, fileStream) => {
// construct FileApi
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config);
// create upload file request
var request = new groupdocs_conversion_cloud.UploadFileRequest("sample-pptx-file", 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);
});
});
// construct FileApi to download converted file
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config);
// create donwload file request
let request = new groupdocs_conversion_cloud.DownloadFileRequest("nodejs-testing/output-sample-file.jpg", 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\\output-sample-file.jpg", response, "binary", function (err) { });
console.log("Expected response type is Stream: " + response.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
# Import Node.js SDK in your node application from http://api.groupdocs.cloud
global.groupdocs_conversion_cloud = require("groupdocs-conversion-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_conversion_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