Convert Word DOC to JPG in Java

In various cases, we need to display MS Word DOC/DOCX into our applications programmatically. One of the most convenient ways in such scenarios is the conversion from DOC or DOCX to JPG format. To accomplish that, in this article, you will learn how to convert DOC or DOCX files to JPG in Java. Furthermore, we will cover how to customize the DOC to JPG conversion using different options.

Java API for DOC DOCX to JPG - Free Download

Aspose.Words for Java is a feature-rich API to create, edit, or convert MS Word documents in Java-based applications. We will use this API to convert DOC/DOCX to JPG. You can download the API’s JAR or install it using the following Maven configurations:

Repository:

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

Dependency:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>22.4</version>
    <classifier>jdk17</classifier>
</dependency>

Convert DOC to JPG in Java

You can convert a DOC/DOCX into JPG, PNG, BMP, GIF, or TIFF images depending upon your requirement. To set the output image format, SaveFormat enum is used. Let’s convert a DOCX file to JPG in Java.

The following code sample shows how to convert a DOCX to JPG in Java.

Java DOCX to JPG - Customization

You can also customize the DOC to PNG conversion using different options. For example, you can set horizontal resolution, vertical resolution, overall resolution, scale, pixel format, brightness, color mode, contrast, etc. The following are the steps to customize DOC to JPG in Java.

  • Load the DOC file using the Document class.
  • Create an instance of ImageSaveOptions class and specify the output image format.
  • Set desired options such as brightness, contrast, etc. using the ImageSaveOptions object.
  • Loop through the pages in the document.
  • Convert each page to JPG using Document.save(string, ImageSaveOptions) method.

The following code sample shows how to customize Java DOC to JPG conversion using different options.

Java DOCX to JPG Converter - Get a Free License

You can get a temporary license in order to use Aspose.Words for Java without evaluation limitations.

Conclusion

In this article, you have learned how to convert Word DOC/DOCX to JPG in Java. Furthermore, you have seen how to customize DOC to JPG conversion using different options. Apart from that, you can explore other features of Aspose.Words for Java using the documentation. Also, you can post your questions on our forum.

See Also