How to convert Word DOCX to PDF in Javascript

Today’s post is going to lay out how to do a quick format change in Javascript, specifically between DOCX and PDF.

We are going to kick off with importing our client via this script tag, which needs to be inserted between the <head>…</head> tags.

<script src="https://cdn.cloudmersive.com/jsclient/cloudmersive-document-convert-client.js"></script>

Next in line, calling our function:

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.convertDocumentDocxToPdf(inputFile, callback);

Give our API a moment and you will be returned your converted file. So easy! There is a separate function specifically for legacy DOC files as well as XLSX and PPTX.

Image for post
Image for post

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