How to Merge Two PowerPoint (PPTX) Documents Together Automatically using Java

Cloudmersive
2 min readJul 7, 2022

--

Managing office documents can be a real inconvenience. PowerPoint documents in particular are notoriously unwieldy and can make merging documents a difficult process. Our PPTX merging API can be included as a service in your application to handle that task automatically, accepting two basic file inputs as parameters. To utilize this API, follow instructions provided in the demonstration below to structure your API call in Java, or visit our API console page to find comparable code available in a dozen additional programming languages. If coding isn’t your thing, you can find this API in Connector form via Power Automate and Azure Logic Apps.

To get set up with Java, let’s first install the Java SDK with Maven. Add a reference to the pom.xml repository:

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

Then add one to the pom.xml dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

With installation finished, let’s add the import classes to the top of the file and call the API:

// 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: Apikey
ApiKeyAuth 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/inputfile"); // File | First input file to perform the operation on.
File inputFile2 = new File("/path/to/inputfile"); // 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();
}

Along with your two input PPTX files, you’ll need to supply a Cloudmersive API to authenticate remote access. To get one, simply register a free account on our website (with your free-tier account, you’ll receive a limit of 800 API calls per month).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet