How to Convert DOC to DOCX using Java

We will explain to you the process to convert DOC to DOCX using Java in this how-to tutorial. We will use one of the popular document conversion libraries for doing document transformation between formats. Further, you do not need to install MS Office and any third-party software for converting documents from DOC to DOCX format. Moreover, we will produce a sample code to show you the implementation of the convert DOC to DOCX Java feature.

Steps to Convert DOC to DOCX using Java

  1. Install GroupDocs.Conversion for Java from the Maven repository in the project to convert DOC to DOCX
  2. Add a reference to the essential classes for performing document conversion from DOC to DOCX
  3. Load the input DOC file by creating an instance of the Converter class
  4. Create an object of the WordProcessingConvertOptions class and set convert options for the output DOCX file
  5. Save the output DOCX file to the disk by calling the Convert method of the Converter class, pass the output file name along with the WordProcessingConvertOptions to it

In these steps, we load the source DOC file into a Converter object after configuring the project with the required library and importing the necessary classes for the implementation of the Java convert DOC to DOCX feature. Then, we customize the output file by creating an instance of the WordProcessingConvertOptions class and setting the convert options for it. In the last step, we use the Convert method for saving the converted document to the disk.

Code to Convert DOC to DOCX using Java

You can see in the above example how easy to create the Java DOC to DOCX capability by following the above points in order. We have produced this sample code by consuming a few API calls and a few lines of code. Further, WordProcessingConvertOptions class can be used to customize the converted document by defining properties such as left margin, right margin, top margin, bottom margin, height, width, page orientation, and many more.

We have created the steps for converting DOC to DOCX in Java and developed a working example for it in this post. Recently, we had published post on converting TIFF to PNG documents in Java, see how to convert TIFF to PNG in Java.

 English