Convert Word DOC to PNG 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 PNG format. To accomplish that, in this article, you will learn how to convert DOC or DOCX files to PNG in Java. Furthermore, we will cover how to customize the DOC to PNG conversion using different options.

Java API for DOC DOCX to PNG - 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 PNG. 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 PNG in Java

You can convert a DOC/DOCX into PNG, JPEG, 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 PNG in Java.

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

Java DOCX to PNG - 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 PNG 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 PNG using Document.save(string, ImageSaveOptions) method.

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

Java DOCX to PNG 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 PNG in Java. Furthermore, you have seen how to customize DOC to PNG 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