Convert Word to PNG using Java

Convert Word to PNG using Java

In the near past, we published a blog post that demonstrates the conversion process of Word to JPG programmatically. This blog post will teach us how to convert Word to PNG using Java image library. This library offers many features to facilitate the developers to build a Word to PNG converter by writing a few lines of source code in Java language. However, you are supposed to have Java set up on your local machine before you start this tutorial.

The following sections will be covered:

Word to PNG converter - library installation

The installation process of this library is straightforward. You can either download the JAR files or follow Maven configurations to set up this library in your Java application.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>21.11</version>
    <type>pom</type>
</dependency>

Convert Word to PNG using Java

You can follow the following steps and the code snippet to develop a Word to PNG conversion module for your business application:

Please follow the steps given below:

  1. Create an instance of the Document class and load the source Word file.
  2. Initialize the constructor of ImageSaveOptions class that allows specifying additional options when rendering document pages or shapes to images.
  3. Invoke the setPageSet method to set 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. Call the setImageContrast method to set the image’s 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 PNG format by calling the save method.

Copy & paste the following code into your main file:

The output can be seen in the image below:

Word to PNG converter

Get a Free License

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

Summing up

We are ending this article at this point. We hope that you have learned how to convert Word to PNG using Java image library. Moreover, you also have explored some advanced methods offered by this enterprise-level library. Finally, do not forget to visit the documentation to know about other great features.

Moreover, we suggest you follow our Getting Started guide.

Finally, conholdate.com is writing new blog posts. So, please stay in touch for regular updates.

Ask a question

You can let us know about your questions or queries on our forum.

FAQs

How do I convert a Word document to a PNG?

Create an instance of the Document class and load the source Word file, and save the document in PNG format by calling the save method.

See Also