How to Convert ODT to PDF in Node.js
Open Document Text (ODT) files are still widely used as an alternative to DOCX. Just like DOCX, ODT content is best presented in PDF as a final product.
Using the below code, we can easily convert ODT files to PDF with a free-to-use API solution. After structuring our request, we can authorize up to 800 API calls per month (zero additional commitments upon reaching that limit) with a free-tier API key.
Let’s first install the SDK. We can do so either by running this command:
npm install cloudmersive-convert-api-client --save
Or by adding the following snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Finally, we can use the below code to make our request and convert our file:
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.convertDocumentOdtToPdf(inputFile, callback);
We can then write our PDF encoding to a new PDF document. Easy!