Java: Convert PowerPoint to Images (PNG, JPG, TIFF, SVG)

In comparison with PowerPoint documents, image files are easier to view because they can be opened on almost any device without the need for specific software. If you want to make your PowerPoint documents accessible on a wide range of devices, you can convert them to images. In this article, we will explain how to convert PowerPoint documents to various image formats in Java using Spire.Presentation for Java.

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>9.9.2</version>
    </dependency>
</dependencies>
    

Convert PowerPoint Documents to JPG or PNG Images in Java

The following are the steps to convert a PowerPoint document to JPG or PNG image:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Iterate through all slides in the PowerPoint document.
  • Save each slide as a BufferedImage object using ISlide.saveAsImage() method.
  • Save the BufferedImage object to PNG or JPG file using ImageIO.write() method.
  • Java
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

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

        //Iterate through all slides in the PowerPoint document
        for(int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            ISlide slide = presentation.getSlides().get(i);
            //Save each slide as PNG image
            BufferedImage image = slide.saveAsImage();
            String fileName = String.format("ToImage-%1$s.png", i);
            ImageIO.write(image, "PNG",new File(fileName));
        }
    }
}

Java: Convert PowerPoint to Images (PNG, JPG, TIFF, SVG)

Convert PowerPoint Documents to TIFF Images in Java

The following are the steps to convert a PowerPoint document to TIFF image:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Convert the PowerPoint document to TIFF image using Presentation.saveToFile(String, FileFormat) method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

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

        //Convert the PowerPoint document to TIFF image
        presentation.saveToFile("toTIFF.tiff", FileFormat.TIFF);
    }
}

Java: Convert PowerPoint to Images (PNG, JPG, TIFF, SVG)

Convert PowerPoint Documents to SVG Images in Java

The following are the steps to convert a PowerPoint document to SVG images:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Convert the PowerPoint document to SVG and save the results into an ArrayList of byte arrays using Presentation.saveToSVG() method.
  • Iterate through the byte arrays in the ArrayList.
  • Get the current byte array using ArrayList.get(int) method.
  • Initialize an instance of FileOutputStream class and save the byte array to an SVG file using FileOutputStream.write() method.
  • Java
import com.spire.presentation.Presentation;

import java.io.FileOutputStream;
import java.util.ArrayList;

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

        //Convert the PowerPoint document to SVG and save the results into an ArrayList of byte arrays
        ArrayList svgBytes =(ArrayList) presentation.saveToSVG();
        int len = svgBytes.size();
        //Iterate through the byte arrays in the ArrayList
        for (int i = 0; i < len; i++)
        {
            //Get the current byte array
            byte[] bytes = svgBytes.get(i);
            //Specify the output file name
            String fileName= String.format("ToSVG-%d.svg", i);
            //Create a FileOutputStream instance
            FileOutputStream stream = new FileOutputStream(fileName);
            //Save the byte array to an SVG file
            stream.write(bytes);
        }
    }
}

Java: Convert PowerPoint to Images (PNG, JPG, TIFF, SVG)

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.