How to Convert ODP to PNG using Node.js
When we convert our presentation files to PNG arrays, we end up with an extremely lightweight & highly interoperable version of our finalized presentation content.
Using the below code, we can easily convert our ODP files to PNG arrays — one image per slide of the original presentation — using a free API solution. We can authorize our requests using a free-tier API key, and this will give us up to 800 API calls per month with no additional commitment (once we reach our limit, our total will just reset the following month).
With our API key copied to our clipboard, we can start the process of structuring our API call by first installing the SDK. We can either run the following command:
npm install cloudmersive-convert-api-client --save
Or we can add the below snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Finally, we can copy the below code examples into our file, and we can paste our free-tier API key in the appropriate line:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();
var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.convertDocumentOdpToPng(inputFile, callback);
Just like that, we can easily incorporate ODP to PNG conversions into our Node.js applications with minimal code.