Convert Word DOCX JPG Image in Java

MS Word to JPG in Java

Install this rich-featured Java library to convert Microsoft Word DOCX or DOC files to image formats such as JPEG/JPG. It offers a wide range of file manipulation and conversion methods. In the recent past, we published an article that demonstrates the conversion of HTML files to Word files programmatically in Java applications. In most scenarios, you need to transform your Word DOCX files to a static file format that cannot be modified easily. Therefore, we will learn how to convert Word DOCX to JPG Image programmatically in Java.

We will cover the following points in this article:

Convert DOCX to JPG Programmatically in Java - API Installation

Equipping your Java application with a Word to JPG converter is very quick now due to the simple and easy installation procedure of this Java library. You can either download the jar files or follow 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>21.11</version>
    <type>pom</type>
</dependency>

How to Convert a Word DOCX to JPG Image in Java

It is a very powerful library that performs optimized file conversion in a few seconds.

You may follow the following steps to convert Word to JPG format programmatically.

  1. Load the source DOCX file by calling the constructor of the Document class.
  2. Call save method to save the file in JPG format.

The code snippet below demonstrates how to convert Word DOCX document to JPG image format in Java:

Convert Word DOCX to JPG Image using Java - Advance Features

You may configure the API calls as per the requirements. Moreover, you can see the list of all available classes and their methods here.

Following are the steps to convert Word to JPG in Java:

  1. Initialize an instance of the Document class and load the source DOCX file.
  2. Create an object of ImageSaveOptions class to specify additional options.
  3. Invoke the setPageSet method to the “PageSet” to “0” to convert only the first page of a document.
  4. Change the image’s brightness by calling the setImageBrightness method.
  5. setImageContrast will set the contrast.
  6. Change the horizontal resolution by calling the setHorizontalResolution method. The default value for these properties is 96.0, for a resolution of 96dpi.
  7. Save the document in JPG format by calling the save method.

The following sample code shows how to convert Word DOCX to a JPG image in Java:

Get a Free License

You can get a free temporary license to try the API without evaluation limitations.

Summing up

This is the end of this blog post. We have covered how to convert MS Word DOCX to JPG image programmatically in Java. In addition, we have gone through the code snippets that elaborate on advanced features provided by this Java library. However, you may explore the other features by navigating to the documentation. Further, conholdate.com is writing other blog posts on new topics. Therefore, please stay in touch for the latest updates.

Ask a question

You may share your questions or queries on our forum.

See Also