How to Convert ODT Files to JPG Arrays using Node.js

Cloudmersive
2 min readNov 10, 2023

--

One major advantage of storing document images in JPG format is the ability to control the quality of the final product.

Using the below code, we can convert our ODT (Open Document Text) files to JPG image arrays — one image per page of the original document — using a free API service in our Node.js application. We can specify the exact quality of our output images through a special request parameter (1 = highest compression, 100 = lowest compression), allowing us to drastically reduce the file size of our JPGs if need be.

All we need to do is follow steps below to structure our API call, and then authorize our request with a free-tier API key (these allow 800 API calls per month with no commitment).

We can begin structuring our request by installing the SDK. We have two methods we can use — either running the below command:

npm install cloudmersive-convert-api-client --save

Or adding this snippet to our package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

Finally, we can authorize our request and call the function:

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 opts = {
'quality': 56 // Number | Optional; Set the JPEG quality level; lowest quality is 1 (highest compression), highest quality (lowest compression) is 100; recommended value is 75. Default value is 75.
};

var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.convertDocumentOdtToJpg(inputFile, opts, callback);

And we’re all set — we’ll receive our JPG array in our response.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet