How to convert PPT to JPG images using Java

How to convert PPT to JPG image using Java

If you are a social media or web marketer, you may need to display PowerPoint presentations on the web. The easiest way to implement this idea is to convert the PPT/PPTX slides to image format such as JPG/JPEG. This article will guide you how to convert PPT to JPG images using Java. Furthermore, we will discuss the conversion of slides to grayscale JPGs and the customization in sizes of the output images.

The following points will be covered in this article:

PPT conversion library installation

In this section, you will learn the installation procedure of this Java conversion library. If you are using Maven to manage a Java project or app, add the following configurations in the pom.xml file.

<repository>
	<id>ConholdateJavaAPI</id>
	<name>Conholdate Java API</name>
	<url>https://releases.conholdate.com/java/repo</url>
</repository>        
<dependency>
	<groupId>com.conholdate</groupId>
	<artifactId>conholdate-total</artifactId>
	<version>23.6</version>
	<type>pom</type>
</dependency>

Then run the following commands.

mvn clean    
mvn install -U

For configurations about other Java frameworks, please visit releases.conholdate.com.

Convert PPT slide to JPG in Java

This section demonstrates the conversion of a single PowerPoint slide into a JPEG image. The following are the steps to do the job.

  1. Load the PowerPoint presentation using Converter class.
  2. Initialize an instance of ImageConvertOptions class and set the conversion file format as JPG.
  3. Invoke Converter.convert(String arg0, ConvertOptions arg1) method to save the JPG image.

The following code sample shows how to convert a single PPT slide to JPG/JPEG image in Java.

Below is a resultant JPG after running the above Java program.

PPTX to JPG image

PPT/PPTX to JPG in grayscale form

So far, we have discussed how to convert PPT to JPG image. In this section, we will see how to get the resultant JPG in grayscale form.

Follow the steps given below:

  1. Load the PPT/PPTX file using Converter class.
  2. Specify the conversion file format as JPG using ImageConvertOptions class.
  3. Enable the grayscale option using setGrayscale(bool) method.
  4. Call Converter.convert(String arg0, ConvertOptions arg1) method to save the output image.

The code sample below shows how to get the output JPG in the grayscale form.

You will see the resultant JPG as follows.

Convert to grayscale image

PPT to JPG conversion in Java - Set the size of JPEG image

In this section, we will use PPT/PPTX to JPG conversion library to specify the dimensions of the resultant images. You can write the code using the steps given below.

  1. Use Converter class to load the presentation.
  2. Initialize the object of ImageConvertOptions class and specify the conversion file format as JPG.
  3. Set the dimensions of the resultant JPG using setHeight(int) and setWidth(int) methods.
  4. Call Converter.convert(String arg0, ConvertOptions arg1) method to save the JPG image.

The following code snippet demonstrates how to set the height and width of the output images while converting PPT slides to JPGs.

Get a free license

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

Conclusion

To conclude, we discussed the conversion of PowerPoint (PPT/PPTX) files to JPEG images. Besides, we converted PPT slides to grayscale JPGs and set the dimensions of the resultant images.

You may visit the documentation to learn more about the Java conversion API.

Finally, we suggest you stay tuned at conholdate.com for regular updates.

Ask a question

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

See also