Convert Word DOC to PNG, JPEG, BMP, GIF, or TIFF in Java

Convert Word DOC to PNG, JPEG, BMP, GIF, or TIFF in Java

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

Java API for Word DOC to Image Conversion

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 Word documents to image formats. 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>

Java Convert a Word DOC to PNG, JPEG, BMP, GIF, or TIFF

You can convert a Word document into PNG, JPEG, BMP, GIF, or TIFF images depending upon your requirement. To set the output image format, SaveFormat enum is used. For demonstration, let’s convert a Word DOCX file to PNG images in Java.

The following code sample shows how to convert a Word DOCX to PNG images in Java.

Customize DOC/DOCX to Image Conversion in Java

You can also customize the Word to image 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 Word to image conversion in Java.

  • Load the Word document 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 image using Document.save(string, ImageSaveOptions) method.

The following code sample shows how to customize Word to JPEG image conversion using different options.

Get a Free API 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 documents to PNG, JPEG, BMP, GIF, or TIFF images in Java. Furthermore, you have seen how to customize Word to image 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