Java: Convert PowerPoint Presentations to PDF

When a PowerPoint presentation is converted to PDF, its document layout and formatting are fixed. Recipients can view the converted document without having Microsoft PowerPoint to be installed, but they can not modify it easily. In this article, we will demonstrate how to convert PowerPoint presentations to PDF in Java using Spire.Presentation for Java library.

Install Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>7.6.3</version>
    </dependency>
</dependencies>

Convert a Whole PowerPoint Presentation to PDF in Java

The following steps show you how to convert a whole PowerPoint presentation to PDF:

  • Initialize an instance of Presentation class.
  • Load the PowerPoint presentation using Presentation.loadFromFile() method.
  • Save it to PDF using Presentation.saveToFile(filePath, FileFormat.PDF) method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

public class ConvertPowerPointToPDF {
    public static void main(String []args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Save it as PDF
        ppt.saveToFile("ToPdf1.pdf", FileFormat.PDF);
    }
}

Java: Convert PowerPoint Presentations to PDF

Convert Specific Slide of a PowerPoint Presentation to PDF in Java

The following steps show you how to convert a specific slide of a PowerPoint presentation to PDF:

  • Initialize an instance of Presentation class.
  • Load the PowerPoint presentation using Presentation.loadFromFile() method.
  • Get the desired slide by its index using Presentation.getSlides().get(slideIndex) method.
  • Save it to PDF using ISlide.saveToFile(filePath, FileFormat.PDF) method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

public class ConvertSlidesToPDF {
    public static void main(String []args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Get the second slide
        ISlide slide= ppt.getSlides().get(1);

        //Save the slide to PDF
        slide.saveToFile("ToPdf2.pdf", FileFormat.PDF);
    }
}

Java: Convert PowerPoint Presentations to PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.