How to merge two PowerPoint PPTX files together in Java

Merging PowerPoint files can be quite a tall order in Java, as this is by no means a simple format to work with or even parse. To help you avoid headaches and gray hairs, today’s tutorial is here to provide you with a simplified solution. You’ll be ready to start merging in no time. Let’s begin.

We will be using Jitpack to dynamically compile our client library, so let’s go ahead with adding that to our repositories.

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

And following that, we have our dependency reference for the Cloudmersive API client.

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>

Now our function call…

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.MergeDocumentApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");MergeDocumentApi apiInstance = new MergeDocumentApi();File inputFile1 = new File("/path/to/file.txt"); // File | First input file to perform the operation on.File inputFile2 = new File("/path/to/file.txt"); // File | Second input file to perform the operation on (more than 2 can be supplied).try {byte[] result = apiInstance.mergeDocumentPptx(inputFile1, inputFile2);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling MergeDocumentApi#mergeDocumentPptx");e.printStackTrace();}

And that’s it!

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store