How to Convert an ODT File to a PNG Image Array using Node.js
When converting to PDF isn’t a viable option, we can convert our ODT files to PNG instead. That way, we can still ensure we have a lightweight, interoperable copy of our finalized content to share.
Thankfully, we can easily make this conversion using the ready-to-run Node.js code examples below. We’ll be taking advantage of a quick, secure and free-to-use API service when we do so, and we can make up to 800 API calls per month with no additional commitment by authorizing our request with a free-tier API key.
Our first step is to install the SDK. We can do so either by running the below command:
npm install cloudmersive-convert-api-client --save
Or by adding this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Following that, we just need to include the below code in our file & provide our API key to make our requests:
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.convertDocumentOdtToPng(inputFile, callback);
And that’s all the code we’ll need. Easy!