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 to JPG conversion library installation
- PPT/PPTX to JPG in Java
- Convert to grayscale image
- Customize dimensions of resultant JPEG image
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.
- Load the PowerPoint presentation using Converter class.
- Initialize an instance of ImageConvertOptions class and set the conversion file format as JPG.
- 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.
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:
- Load the PPT/PPTX file using Converter class.
- Specify the conversion file format as JPG using ImageConvertOptions class.
- Enable the grayscale option using setGrayscale(bool) method.
- 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.
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.
- Use Converter class to load the presentation.
- Initialize the object of ImageConvertOptions class and specify the conversion file format as JPG.
- Set the dimensions of the resultant JPG using setHeight(int) and setWidth(int) methods.
- 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.
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.
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.