How to convert HTML to a Word DOCX Document in Salesforce Apex

Cloudmersive
1 min readFeb 16, 2020

I think we can all agree that nobody wants to deal with file format conversion. It’s finicky, inconvenient, and frustrating. So why not make it easy on yourself? We’ve got just the API for you.

First we need to download and unzip our Apex Client to your project’s folder.

Now that our client is accessible, we are able to invoke convertWebHtmlToDocx:

SwagConvertWebApi api = new SwagConvertWebApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'inputRequest' => SwagHtmlToOfficeRequest.getExample()};try {// cross your fingersBlob result = api.convertWebHtmlToDocx(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Easy. Now go enjoy all that time you just saved.

--

--

Cloudmersive

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