Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert PDF to PowerPoint using REST API in Node.js

Learn how to convert PDF to PowerPoint using a REST API in Node.js: https://blog.groupdocs.cloud/2021/11/26/convert-pdf-to-powerpoint-using-rest-api-in-node-js/

The following topics shall be covered in this article:

  1. PDF to PowerPoint Conversion REST API and Node.js SDK
  2. Convert PDF to PowerPoint using REST API in Node.js
  3. PDF to PPTX Conversion with Watermark using Node.js
  4. Convert Range of Pages from PDF to PPTX in Node.js
  5. Convert Specific Pages from PDF to PPTX in Node.js
  6. PDF to PPTX Conversion without using Cloud Storage
global.clientId = "da0c487d-c1c0-45ae-b7bf-43eaf53c5ad5";
global.clientSecret = "479db2b01dcb93a3d4d20efb16dea971";
global.myStorage = "";
const config = new groupdocs_conversion_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";
// Initialize api
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
// Read the input file
let file = fs.readFileSync('C:\\Files\\Conversion\\sample.pdf');
// Create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentDirectRequest("pptx", file);
// Convert document
let result = await convertApi.convertDocumentDirect(request);
// Save the output file
fs.writeFile("C:\\Files\\Conversion\\sample_direct.pdf", result, "binary", function (err) { });
// Api initialization
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
// Define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.filePath = "sample.pdf";
settings.format = "pptx";
settings.outputPath = "converted_with_watermark.pptx";
// Define watermark options
let watermark = new groupdocs_conversion_cloud.WatermarkOptions();
watermark.text = "CONFIDENTIAL";
watermark.bold = true;
watermark.fontSize = 30;
watermark.color = "Gray";
watermark.background = false;
watermark.rotationAngle = 0;
watermark.left = 200;
watermark.top = 250;
// Define convert options
let convertOptions = new groupdocs_conversion_cloud.PresentationConvertOptions();
convertOptions.watermarkOptions = watermark;
settings.convertOptions = convertOptions
// Define convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// Convert document
let result = await convertApi.convertDocument(request);
console.log("Document converted successfully: " + result[0].url);
// Initialize api
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
// Define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.filePath = "sample.pdf";
settings.format = "pptx";
settings.outputPath = "sample.pptx";
// Create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// Convert document
let result = await convertApi.convertDocument(request);
// Initialize api
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
// Define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.filePath = "sample.pdf";
settings.format = "pptx";
settings.outputPath = "convert_pages_range.pptx";
// Define convert options
let convertOptions = new groupdocs_conversion_cloud.PresentationConvertOptions();
convertOptions.fromPage = 1;
convertOptions.pagesCount = 2;
settings.convertOptions = convertOptions
// Create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// Convert document
let result = await convertApi.convertDocument(request);
console.log("Document converted successfully: " + result[0].url);
// Initialize api
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
// Define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.filePath = "sample.pdf";
settings.format = "pptx";
settings.outputPath = "specific_pages.pptx";
// Define convert options
let convertOptions = new groupdocs_conversion_cloud.PresentationConvertOptions();
convertOptions.pages = [2,3];
settings.convertOptions = convertOptions
// Create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// Convert document
let result = await convertApi.convertDocument(request);
console.log("Document converted successfully: " + result[0].url);
// Construct FileApi
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config);
// Create donwload file request
let request = new groupdocs_conversion_cloud.DownloadFileRequest("sample.pptx", myStorage);
// Download file
let response = await fileApi.downloadFile(request);
// Save in your working directory
fs.writeFile("C:\\Files\\Conversion\\sample.pptx", response, "binary", function (err) { });
// Open file in IOStream from local/disc.
var resourcesFolder = 'C:\\Files\\Conversion\\sample.pdf';
// 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.pdf", 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