How to Convert a PowerPoint to PDF in Java
Convert Office PowerPoint Documents (pptx) and Office PowerPoint (97-2003) Documents (ppt) to standard PDF
Join the DZone community and get the full member experience.
Join For FreeYou use PowerPoint to present findings and data or propose new ideas, whether its within your team, to investors, or to clients. With the ability to choose graphics and color schemes that help reflect your tone and brand, it is a wonderful tool in helping educate and persuade your audience. The simplicity and visual appeal of PowerPoint slides has made it the go-to application for presentation design, and it is used as the default presentation software for many organizations.
Having your PowerPoint converted to PDF format will give you the ability to more easily share information with your audience. This simple act will help your audience remember your organization, and they can use the document as reference when making any decisions. For example, you might use PowerPoint to create a brochure template that could then be populated with client data using input text; this customized brochure could then be converted to PDF using this API in Java and shared with clients for a personalized experience. However, you might even need it for something as simple as converting your PowerPoint to PDF to print and provide as notes for your audience. All of this will help show your professionalism and preparedness.
To access all these benefits, and work without fear of formatting errors caused by the conversion, you can use the following Convert APIs to quickly and easily convert any PPTX or PPT to PDF using Java.
The PPTX format is the most up-to-date in PowerPoint and is compatible with current Office software. To begin the conversion process with the following API, you will first need to install our reference client.
To install with Maven, add a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then, add a reference to the dependency in pom.xml:
xxxxxxxxxx
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>
If you’d like to install with Gradle, add this code block in your root build.gradle at the end of repositories:
x
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then, add the dependency in build.gradle:
xxxxxxxxxx
dependencies {
implementation 'com.github.Cloudmersive:Cloudmersive.APIClient.Java:v3.54'
}
After these install steps, you can call the function, ConvertDocumentPptxToPdf:
xxxxxxxxxx
// 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.ConvertDocumentApi;
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");
ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
byte[] result = apiInstance.convertDocumentPptxToPdf(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentPptxToPdf");
e.printStackTrace();
}
Now, you can fully automate the conversion process from PPTX to PDF. However, what happens if you are working with an older version of PowerPoint? If you need to run the function on a PPT file, the process is very similar. We start with the same install steps for our client software, as shown above.
Now, you can call your function for PPT, ConvertDocumentPptToPdf:
// 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.ConvertDocumentApi;
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");
ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
byte[] result = apiInstance.convertDocumentPptToPdf(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentPptToPdf");
e.printStackTrace();
}
In order to call this function effectively, retrieve your API Key at no cost from the Cloudmersive website. Our base level access provides up to 800 calls across our library of APIs, and we can provide higher levels of service scalable to your needs and software demands.
Opinions expressed by DZone contributors are their own.
Comments