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
- How to convert a Word file to JPG in Java
- Java library to convert Word to JPG programmatically - Advance features
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.
<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>
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.
- Load the source DOCX file by calling the constructor of the Document class.
- 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:
- Initialize an instance of the Document class and load the source DOCX file.
- Create an object of ImageSaveOptions class to specify additional options.
- Invoke the setPageSet method to the “PageSet” to “0” to convert only the first page of a document.
- Change the image’s brightness by calling the setImageBrightness method.
- setImageContrast will set the contrast.
- Change the horizontal resolution by calling the setHorizontalResolution method. The default value for these properties is 96.0, for a resolution of 96dpi.
- 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.
This is the end of this blog post. We have covered how to convert 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, conholdate.com 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.