Convert PPT to JPG in Java

Convert PPT to JPG online
Learn how to convert PPT to JPG online

MS PowerPoint enables the user to create dynamic, informational slides through the use of text, graphics, and animation. Therefore, PowerPoint formats (PPT / PPTX / OTP / ODP, etc) have become very popular for information presentation. However, in order to view or edit these files, specific applications, especially on mobile devices. So in this article, we are going to discuss the details to convert PPT to JPG online.

PowerPoint Conversion API

Aspose.Slides Cloud SDK for Java provides the capabilities to create, edit and render PowerPoint slides to other Supported Document Formats. So in order to use the SDK, first we need to install it. Please enter the following details in pom.xml of the maven build project to install the SDK.

<repositories>
 <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>http://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>
<dependencies>
 <dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides-cloud</artifactId>
    <version>21.3.0</version>
 </dependency>
</dependencies>

After the installation, we need to create an account by visiting Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up. Otherwise, create a new Account and obtain your Client Credentials.

Convert PPT to JPG in Java

In order to render the PowerPoint presentation in JPG format, please follow the steps defined below.

  • First of all, create an object of SlidesApi while providing ClientID and ClientSecret details as arguments
  • Secondly, create an object of PutSlideSaveAsRequest class
  • Thirdly, call the setFormat(…) method of PutSlideSaveAsRequest and pass JPEG value from SlideExportFormat enumeration
  • Now call the setName(…) method of PutSlideSaveAsRequest class to provide name of input PPTX file
  • In order to specify the name of the resultant file, use the setOutPath(…) method from PutSlideSaveAsRequest class
  • Penultimate, call the setSlideIndex(..) method to specify the index of the PowerPoint slide to be converted
  • Finally, call the putSlideSaveAs(…) method of SlidesAPi class and pass PutSlideSaveAsRequest object as argument
PPT to JPG preview
Image 1:- PPT to JPG conversion preview.

The sample files used in the above example can be downloaded from the following links

Convert PPT to PNG in Java

In the following example, we are going to discuss the details of how to upload a PowerPoint presentation from a local system and convert it to PNG format in the cloud.

  • First, we need to create an object of SlidesApi which takes ClientID and ClientSecret as input arguments
  • The next step is to load a Presentation file from local storage into a byte[] array
  • Create an instance of PutExportSlideRequest class
  • In order to specify the output format, please use setFormat(….) method of PutExportSlideRequest class and pass the PNG value from SlideExportFormat enumeration
  • The input file is passed using setDocument(…) method which takes a byte[] array as an argument
  • Now we need to specify the index of the slide to be converted using the setSlideIndex(..) method
  • In order to specify the name of the resultant file, use the setOutPath(…) method
  • Finally, call the putExportSlide(…) method which takes the PutExportSlideRequest object as an argument to perform the conversion
PPT to PNG preview
Image 2:- PPT to PNG conversion preview.

The sample input and output files used in the above example are available for download on the following links

PowerPoint to JPG using cURL Commands

The cURL commands are an exciting way to access REST APIs on any platform. So first we need to generate JSON Web Token (JWT) based on your ClientID and ClientSecret details retrieved from Aspose.Cloud dashboard. Therefore, please execute the following command in the terminal to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once we have the JWT token, use the following command to convert existing PowerPoint in Cloud storage to JPEG format. We have used PostSlidesSplit API which splits the presentation file and creates an image of each slide. In our scenario, we have provided a range from slides 1 to 1.

curl -X POST "https://api.aspose.cloud/v3.0/slides/Presentation1.pptx/split?format=Jpeg&from=1&to=1" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"DefaultRegularFont\": \"string\",  \"Format\": \"jpeg\"}"

Convert PPT to PNG using cURL Command

The slides of the PowerPoint presentation can be easily converted to PNG format. Use the following command to perform the conversion.

curl -X POST "https://api.aspose.cloud/v3.0/slides/Presentation1.pptx/split?format=Png&width=1000&height=600&from=1&to=1" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"DefaultRegularFont\": \"string\",  \"Format\": \"png\"}"

Conclusion

This article has explained the details on how to convert PPT to JPG and PPT to PNG using Java SDK. We have explored the options to perform the conversion using Java code snippets as well as using the cURL commands. Please note that the Cloud SDK is open-source and its complete source code is available on GitHub. In case you encounter any issues while using the SDK, please feel free to contact us through the Free customer support forum.

Related articles

We also recommend visiting the following links for details on