How to convert Excel XLSX to PDF in Node.js

Cloudmersive
Apr 22, 2019 · 1 min read

The first step is to add a reference to our package.json for the document processing library:

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

Now, all we have to do is call convertDocumentXlsxToPdf to convert our Excel Document (XLSX) format file into a PDF 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.convertDocumentXlsxToPdf(inputFile, callback);

That’s all there is to it, and it is free.

Note that this function is specifically for XLSX. Other functions are available for XLS, as well as auto-detection of the document type and generalized conversion into PDF.

You can also use this library to convert XLSX files into JSON, and even enumerate and manipulate the contents of the XLSX file, for example to add or remove a header, watermark, row of data, etc.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade