Convert Word to Image (JPG) Programmatically in Java

MS Word to JPG in Java

Install this rich-featured Java library to convert Microsoft Word files to image formats such as JPEG/JPG. It offers a wide range of file manipulation and conversion methods. In the near 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 files to a static file format that cannot be modified easily. Therefore, we will learn how to convert Word to JPG 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.


    <name>Aspose Java API</name>



How to convert a Word file to JPG in Java

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

You may follow the following steps and the code snippet 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

Java library to convert Word to JPG programmatically - 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 and the code snippet 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.

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 to JPG 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, 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