How to Convert Microsoft PowerPoint to PDF with Java

Convert PowerPoint presentations into portable PDF files with Java.
Share this page

By the end of this tutorial, you'll know how to convert Microsoft PowerPoint to PDF with Java and the Convert to PDF API Tool. The walkthrough identifies the presentation through its filename and media type, requests PDF output, and reads the generated resource details without presentation software. We'll explain the important request pieces so you can use the sample as the foundation for an integration that can convert Microsoft PowerPoint to PDF.

Why Convert Microsoft PowerPoint to PDF with Java?

A training portal may need to publish approved slides without requiring presentation software or exposing an editable deck. Converting the presentation creates a stable document for browser viewing and download.

The adapted example sends a .pptx file with the PowerPoint Open XML media type. The output name is supplied separately, while the API response identifies the generated PDF resource.

Java Code Example

import io.github.cdimascio.dotenv.Dotenv;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.*;
import org.json.JSONObject;

public class ConvertPowerPointToPDF {

  // By default, we use the US-based API service. This is the primary endpoint for global use.
  private static final String API_URL = "https://api.pdfrest.com";

  // For GDPR compliance and enhanced performance for European users, you can switch to the EU-based
  // service by commenting out the URL above and uncommenting the URL below.
  // For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
  // private static final String API_URL = "https://eu-api.pdfrest.com";

  // Specify the path to your file here, or as the first argument when running the program.
  private static final String DEFAULT_FILE_PATH = "/path/to/file.pptx";

  // Specify your API key here, or in the environment variable PDFREST_API_KEY.
  // You can also put the environment variable in a .env file.
  private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

  public static void main(String[] args) {
    File inputFile;
    if (args.length > 0) {
      inputFile = new File(args[0]);
    } else {
      inputFile = new File(DEFAULT_FILE_PATH);
    }

    final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load();

    final RequestBody inputFileRequestBody =
        RequestBody.create(inputFile, MediaType.parse("application/vnd.openxmlformats-officedocument.presentationml.presentation"));
    RequestBody requestBody =
        new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("file", inputFile.getName(), inputFileRequestBody)
            .addFormDataPart("output", "pdfrest_powerpoint_to_pdf")
            .build();
    Request request =
        new Request.Builder()
            .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY))
            .url(API_URL + "/pdf")
            .post(requestBody)
            .build();
    try {
      OkHttpClient client =
          new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();

      Response response = client.newCall(request).execute();
      System.out.println("Result code " + response.code());
      if (response.body() != null) {
        System.out.println(prettyJson(response.body().string()));
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  private static String prettyJson(String json) {
    // https://stackoverflow.com/a/9583835/11996393
    return new JSONObject(json).toString(4);
  }
}

Source: Java sample on GitHub. For this tutorial, the general Java source has been tailored to the Convert Microsoft PowerPoint to PDF input or task.

Breaking Down the Code

Load the Java HTTP and JSON dependencies

import io.github.cdimascio.dotenv.Dotenv;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.*;
import org.json.JSONObject;

The supporting code combines OkHttp networking with dotenv configuration and org.json processing.

Choose the input and load credentials

// service by commenting out the URL above and uncommenting the URL below.
  // For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
  // private static final String API_URL = "https://eu-api.pdfrest.com";

  // Specify the path to your file here, or as the first argument when running the program.
  private static final String DEFAULT_FILE_PATH = "/path/to/file.pptx";

  // Specify your API key here, or in the environment variable PDFREST_API_KEY.
  // You can also put the environment variable in a .env file.
  private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

  public static void main(String[] args) {
    File inputFile;
    if (args.length > 0) {
      inputFile = new File(args[0]);
    } else {
      inputFile = new File(DEFAULT_FILE_PATH);
    }

    final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load();

    final RequestBody inputFileRequestBody =

This setup supports quick local testing while allowing normal callers to provide their own path and PDFREST_API_KEY.

Build the multipart request body

final RequestBody inputFileRequestBody =
        RequestBody.create(inputFile, MediaType.parse("application/vnd.openxmlformats-officedocument.presentationml.presentation"));
    RequestBody requestBody =
        new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("file", inputFile.getName(), inputFileRequestBody)
            .addFormDataPart("output", "pdfrest_powerpoint_to_pdf")
            .build();
    Request request =
        new Request.Builder()
            .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY))
            .url(API_URL + "/pdf")
            .post(requestBody)
            .build();
    try {
      OkHttpClient client =
          new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();

The adapted example sends a .pptx file with the PowerPoint Open XML media type. The output name is supplied separately, while the API response identifies the generated PDF resource. The body construction collects the named parts before OkHttp calculates the final multipart header and body encoding.

Send the request to pdfRest

.build();
    Request request =
        new Request.Builder()
            .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY))
            .url(API_URL + "/pdf")
            .post(requestBody)
            .build();
    try {
      OkHttpClient client =
          new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();

This builder chain adds the API key header, selects the operation URL, and attaches the prepared body; changing the base constant switches between US and EU service hosts.

Read the API response

OkHttpClient client =
          new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();

      Response response = client.newCall(request).execute();
      System.out.println("Result code " + response.code());
      if (response.body() != null) {
        System.out.println(prettyJson(response.body().string()));
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  private static String prettyJson(String json) {
    // https://stackoverflow.com/a/9583835/11996393
    return new JSONObject(json).toString(4);

This completion path shows the raw outcome for learning purposes; production code can retain output IDs and branch on reported errors.

Beyond the Tutorial

By working through this example, you now have a Java pattern you can use to convert Microsoft PowerPoint to PDF. With that foundation, you can apply the pattern to training decks, sales presentations, board materials, and presentation archives.

When this becomes part of an application, keep in mind that pDF output represents a static document rather than an interactive presentation, so review slides that depend on animation, embedded media, uncommon fonts, or complex effects. Confirm slide order and visual fidelity before publishing the generated file to a portal or archive.

API Lab lets you try the Convert Microsoft PowerPoint to PDF operation without first building an application. When you are ready to implement it, see the Convert to PDF API Tool documentation for the complete API contract.

Note: The Convert Microsoft PowerPoint to PDF example above uses multipart form data; for callers that have already uploaded the source, review how the JSON payload example constructs the request.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.