How to Convert ODS to PDF in Node.js
In much the same way as XLSX files, it makes sense to create PDF versions of ODS spreadsheets when we’re ready to publish and share our data.
Using the below code, we can easily and conveniently convert ODS to PDF with a simple API solution. We’ll just need a free-tier API key to authorize our request — which we can get on the Cloudmersive website — and we’ll be able to make up to 800 conversions per month with zero additional commitment.
Let’s start by installing the SDK. We can either run the following command:
npm install cloudmersive-convert-api-client --save
Or we can add the following snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Finally, we can include the below examples in our file and include our API key to authorize our request:
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.convertDocumentOdsToPdf(inputFile, callback);
Now it’s quick & easy to convert ODS to PDF in any of our applications.