How to split a single Word DOCX into Separate Documents by Page in Java

2 min readAug 7, 2020


Splitting documents programmatically is Java is chore of epic proportions. If you have ever tried parsing a DOCX file, then you know what I am talking about. If you would rather not spend the rest of your weeks dealing with the problem, then I have just the solution for you. We will use an API library that can get this done for us in no time at all.

First we need a respository reference for Jitpack.


Next comes our dependency for our client.


And lastly, our function call.

// 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.SplitDocumentApi;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");SplitDocumentApi apiInstance = new SplitDocumentApi();File inputFile = new File("/path/to/file"); // File | Input file to perform the operation on.Boolean returnDocumentContents = true; // Boolean | Set to true to return the contents of each Worksheet directly, set to false to only return URLs to each resulting document.  Default is true.try {SplitDocxDocumentResult result = apiInstance.splitDocumentDocx(inputFile, returnDocumentContents);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling SplitDocumentApi#splitDocumentDocx");e.printStackTrace();}

Done! Talk about easy.




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