How to Convert a Word DOCX Document to a Legacy Word Doc (97–03) using Java
In a few recent articles, I’ve demonstrated APIs which you can use to convert your legacy Word Documents to modern (DOCX) documents & PDFs with simple code examples. In this article, I’ll demonstrate how to send your DOCX files in the opposite direction and convert them back to Legacy (97–03) Word Documents with ease. All you need to do is follow instructions below to install the API client and copy ready-to-run code examples provided from our API console (in addition, you’ll need to register a free account on our website to get an API key to authenticate the operation).
We’ll begin API client installation by first adding a reference to the pom.xml repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
And then adding one to the dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
With installation all wrapped up, we can now add our imports and call the function using the examples below. Include your API key & inputFile paths in the appropriate fields (indicated by the code comments):
// 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.ConvertDocumentApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth 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");ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
byte[] result = apiInstance.convertDocumentDocxToDoc(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentDocxToDoc");
e.printStackTrace();
}
After that, you’re all done — no more code required. Simple as can be!