How to get the body from a Word DOCX document in Java

If you have ever tried your hand at parsing DOCX format, then you surely are aware of how difficult and time consuming this process is to set up. In answer to this problem, we have today’s tutorial, which will show you how to rapidly set up a means by which you can extract the body component from any Word document.

To begin, we are going to need to add a reference to Jitpack to your Maven file, which we will be using to compile our library.


Next comes a dependency reference for said client library:


With that out of the way, we are free to call our desired function, in this case editDocumentDocxBody.

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.EditDocumentApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");EditDocumentApi apiInstance = new EditDocumentApi();GetDocxBodyRequest reqConfig = new GetDocxBodyRequest(); // GetDocxBodyRequest | Document input requesttry {GetDocxBodyResponse result = apiInstance.editDocumentDocxBody(reqConfig);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditDocumentApi#editDocumentDocxBody");e.printStackTrace();}


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