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 Maven configuration below.

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 these steps to convert Word to JPG format programmatically.

  1. Load the source DOCX file by creating a new Document object.
  2. Call the save method to write the file in JPG format.

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

Convert Word DOCX to JPG Image using Java - Advance Features

You may configure the API calls as needed. The full list of classes and methods is available here.

Follow these steps to convert Word to JPG in Java:

  1. Initialize a Document instance and load the source DOCX file.
  2. Create an ImageSaveOptions object to set additional options.
  3. Use the setPageSet method with a value of 0 to convert only the first page.
  4. Adjust image brightness with the setImageBrightness method.
  5. Set image contrast using setImageContrast.
  6. Change horizontal resolution via setHorizontalResolution; the default is 96 dpi.
  7. Save the document in JPG format by calling the save method.

The sample code below shows how to convert Word DOCX to a JPG image with advanced options:

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 reviewed code snippets that demonstrate advanced features of this Java library. Explore more capabilities in the documentation. Further, conholdate.com publishes other blog posts on new topics, so stay tuned for the latest updates.

Ask a question

You may share your questions or queries on our forum.

See Also