How to convert Word DOCX to PDF in Javascript

Cloudmersive
1 min readMar 9, 2020

--

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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet