How to Convert Word DOC (97–03) Document to PDF in Node.JS

Any time you have to deal with the legacy Microsoft Word DOC file format, everything just becomes a little bit more annoying. Generally speaking, it’s a lot nicer to simply remove the formatting from the equation by switching it over to something better, like PDF. Most Node.JS users will know that this is not an easy thing to set up, that is, until you see the method on display today. Stay tuned.

We begin with npm install, which we will use to set up our client.

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

Following this, call our function as seen below.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();var inputFile = "/path/to/file"; // 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.convertDocumentDocToPdf(inputFile, callback);

OK, we are already done. Yup, super simple.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store