Convert PowerPoint Presentations to Markdown in Java

Presentation content often ends up in a documentation site, a code repository or a knowledge base, where Markdown fits better: changes can be diffed line by line, and a static site generator can render the file as it stands. Transcribing the slides by hand takes time, and heading levels and list indentation tend to drift on the way across.

Spire.Presentation for Java reads a .pptx file on the server and writes Markdown, so no Microsoft PowerPoint installation is needed in the runtime environment.

Tutorial overview


Setting up the environment

Add Spire.Presentation for Java to the project before starting the conversion.

Why Spire.Presentation for Java

A PowerPoint presentation cannot export Markdown on its own, so the conversion needs a component that can parse the structure of the slides. Spire.Presentation for Java covers a whole deck, several consecutive slides and a single slide, with one method each for loading and writing, and no Office installation is required.

Installing Spire.Presentation for Java

For a Maven project, add the following configuration to the pom.xml file to import the JAR:

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

Without Maven, download the Spire.Presentation for Java package and add the JAR file to the project's classpath.

Convert PowerPoint presentations to Markdown

Titles, sections and tables are kept in the Markdown, and the result can go straight into a repository or a site generator. The scope is chosen to fit: the whole deck, several consecutive slides or a single slide. All three load the presentation the same way; the difference is whether Presentation or ISlide writes the file.

1. Convert a whole presentation to Markdown

Converting the whole deck needs no slide range: the file is read once and written once, in the order the slides are shown.

To convert a whole PowerPoint presentation to Markdown, loading and writing each take one method:

Syntax Result
presentation.loadFromFile("data/Sample.pptx") Loads the presentation to convert from the project's data directory
presentation.saveToFile("WholePresentation.md", FileFormat.Markdown) Writes the whole presentation to a Markdown file
presentation.dispose() Releases the resources held by the Presentation object

The steps are:

  1. Create a Presentation object with new Presentation().
  2. Load the sample presentation with presentation.loadFromFile.
  3. Pass the output file name and FileFormat.Markdown to presentation.saveToFile.
  4. Release the resources held by the Presentation object with presentation.dispose.
import com.spire.presentation.*;

public class ConvertWholePresentation {

    public static void main(String[] args) throws Exception {
        // Create a Presentation object
        Presentation presentation = new Presentation();

        // Load the sample presentation
        presentation.loadFromFile("data/Sample.pptx");

        // Save the whole presentation as a Markdown file
        presentation.saveToFile("WholePresentation.md", FileFormat.Markdown);

        // Release the resources held by the Presentation object
        presentation.dispose();
    }
}

The Markdown file after converting the whole presentation:

Convert a whole PowerPoint presentation to Markdown

2. Convert multiple slides to Markdown

When only part of a presentation is needed, pass a start and an end number and only that stretch is exported; nothing outside it reaches the result.

To convert multiple slides to Markdown, saveToFile takes a start and an end number ahead of the output file name and the target format:

Syntax Result
presentation.saveToFile(1, 3, "SelectedSlides.md", FileFormat.Markdown) Writes slides 2 to 4 to a Markdown file

The steps are:

  1. Create a Presentation object with new Presentation().
  2. Load the sample presentation with presentation.loadFromFile.
  3. Pass the start number 1, the end number 3, the output file name and FileFormat.Markdown to presentation.saveToFile.
  4. Release the resources held by the Presentation object with presentation.dispose.
import com.spire.presentation.*;

public class ConvertSelectedSlides {

    public static void main(String[] args) throws Exception {
        // Create a Presentation object
        Presentation presentation = new Presentation();

        // Load the sample presentation
        presentation.loadFromFile("data/Sample.pptx");

        // Save slides 2 to 4 as a Markdown file
        presentation.saveToFile(1, 3, "SelectedSlides.md", FileFormat.Markdown);

        // Release the resources held by the Presentation object
        presentation.dispose();
    }
}

The Markdown file after converting slides 2 to 4:

Convert multiple slides to Markdown

3. Convert a specified slide to Markdown

When only one slide is needed, take it out of the slide collection and write it with ISlide; the result file holds that slide only.

To convert a specified slide to Markdown, the writing is done by the ISlide object taken out of the collection:

Syntax Result
presentation.getSlides().get(1) Takes the second slide out of the collection and returns it as an ISlide
slide.saveToFile("SingleSlide.md", FileFormat.Markdown) Writes that one slide to a Markdown file

The steps are:

  1. Create a Presentation object with new Presentation() and load the sample presentation with presentation.loadFromFile.
  2. Take the second slide by index with presentation.getSlides().get(1) and assign it to an ISlide variable.
  3. Pass the output file name and FileFormat.Markdown to slide.saveToFile to write that one slide out as a Markdown file.
  4. Release the resources held by the Presentation object with presentation.dispose.
import com.spire.presentation.*;

public class ConvertSingleSlide {

    public static void main(String[] args) throws Exception {
        // Create a Presentation object
        Presentation presentation = new Presentation();

        // Load the sample presentation
        presentation.loadFromFile("data/Sample.pptx");

        // Take the second slide out of the collection
        ISlide slide = presentation.getSlides().get(1);

        // Save that slide as a Markdown file
        slide.saveToFile("SingleSlide.md", FileFormat.Markdown);

        // Release the resources held by the Presentation object
        presentation.dispose();
    }
}

The Markdown file after converting the second slide:

Convert a specified slide to Markdown


Summary

Converting PowerPoint presentations to Markdown in Java is essentially reading the structure of the slides and writing it out as text. Markdown is lightweight and widely supported, which makes it a good fit for code repositories as well as documentation sites and knowledge bases. With Spire.Presentation for Java set up and the sample code in this article, the conversion can be automated, reducing manual work and improving efficiency.

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.


FAQ

Do the slide numbers in saveToFile start at 0 or at 1?

Cause: The start and end numbers of Presentation and the index of getSlides().get(index) all count 0 as the first slide, and both ends of the range are included. Passing 1 and 3 gives slides 2 to 4, three slides in all.

Solution: To export the first N slides, pass 0 and N - 1; getSlides().get(0) likewise takes the first slide. For a single slide, call slide.saveToFile on that slide instead of building a range.

Does the conversion require Microsoft PowerPoint to be installed?

Cause: Spire.Presentation for Java is a standalone Java library that parses .pptx files itself; it does not rely on other Office components.

Solution: The runtime environment needs only a JDK and the project dependencies; no Microsoft PowerPoint or other Office component is required.

Why are the images and speaker notes missing from the converted Markdown?

Cause: The Markdown result is text-based; images are not turned into image links, and speaker notes are not written to the result file.

Solution: To keep images and layout, convert to HTML or PDF instead; if images are needed, add image references to the converted file afterwards.

Published in Conversion

Picture files are among the most commonly used types of documents in people's lives. Sometimes, you may want to take all image files in a folder and convert them into slides for a PowerPoint presentation. Depending on your requirements, you can convert images to shapes or slide backgrounds. This article demonstrates how to convert images (in any common image format) to a PowerPoint document in Java using Spire.Presentation for Java.

Install Spire.Presentation for Java

First, 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>11.10.4</version>
    </dependency>
</dependencies>

Convert Images to Backgrounds in PowerPoint in Java

When images are converted as background of each slide in a PowerPoint document, they cannot be moved or scaled. The following are the steps to convert a set of images to a PowerPoint file as background images using Spire.Presentation for Java.

  • Create a Presentation object.
  • Set the slide size type to Sreen16x9.
  • Get the image paths from a folder.
  • Traverse through the images.
  • Get a specific image and append it to the image collection of the document using Presentation.getImages().append() method.
  • Add a slide to the document using Presentation.getSlides().append() method.
  • Set the image as the background of the slide using the methods under SlideBackground object.
  • Save the document to a PowerPoint file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

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

public class ConvertImagesAsBackground {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Set slide size type
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Remove the default slide
        presentation.getSlides().removeAt(0);

        //Get image files from a folder
        File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
        File[] picFiles  = directoryPath.listFiles();

        //Loop through the images
        for (int i = 0; i < picFiles.length; i++)
        {
            //Add a slide
            ISlide slide = presentation.getSlides().append();

            //Get a specific image
            String imageFile = picFiles[i].getAbsolutePath();

            //Append it to the image collection
            BufferedImage bufferedImage =  ImageIO.read(new FileInputStream(imageFile));
            IImageData imageData = presentation.getImages().append(bufferedImage);

            //Set the image as the background image of the slide
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //Save to file
        presentation.saveToFile("output/ImagesToBackground.pptx", FileFormat.PPTX_2013);
    }
}

Java: Convert Images (PNG, JPG, BMP, etc.) to PowerPoint

Convert Images to Shapes in PowerPoint in Java

If you would like the images are moveable and resizable in the PowerPoint file, you can convert them as shapes. Below are the steps to convert images to shapes in a PowerPoint document using Spire.Presentation for Java.

  • Create a Presentation object.
  • Set the slide size type to Sreen16x9.
  • Get the image paths from a folder.
  • Traverse through the images.
  • Get a specific image and append it to the image collection of the document using Presentation.getImages().append() method.
  • Add a slide to the document using Presentation.getSlides().append() method.
  • Add a shape with the size equal to the slide using ISlide.getShapes().appendShape() method.
  • Fill the shape with the image using the methods under FillFormat object.
  • Save the document to a PowerPoint file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

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

public class ConvertImageToShape {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Set slide size type
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Remove the default slide
        presentation.getSlides().removeAt(0);

        //Get image files from a folder
        File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
        File[] picFiles  = directoryPath.listFiles();

        //Loop through the images
        for (int i = 0; i < picFiles.length; i++)
        {
            //Add a slide
            ISlide slide = presentation.getSlides().append();

            //Get a specific image
            String imageFile = picFiles[i].getAbsolutePath();

            //Append it to the image collection
            BufferedImage bufferedImage =  ImageIO.read(new FileInputStream(imageFile));
            IImageData imageData = presentation.getImages().append(bufferedImage);

            //Add a shape with the size equal to the slide
            IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(0, 0, (float) presentation.getSlideSize().getSize().getWidth(), (float)presentation.getSlideSize().getSize().getHeight()));

            //Fill the shape with image
            shape.getLine().setFillType(FillFormatType.NONE);
            shape.getFill().setFillType(FillFormatType.PICTURE);
            shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            shape.getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //Save to file
        presentation.saveToFile("output/ImagesToShape.pptx", FileFormat.PPTX_2013);
    }
}

Java: Convert Images (PNG, JPG, BMP, etc.) to PowerPoint

Convert Images to PowerPoint with Customized Slide Size in Java

If the aspect ratio of your images is not 16:9, or they are not in a standard slide size, you can create slides based on the actual size of the pictures. This will prevent the image from being over stretched or compressed. The following are the steps to convert images to a PowerPoint document with customized slide size using Spire.Presentation for Java.

  • Create a Presentation object.
  • Create a PdfUnitConvertor object, which is used to convert pixel to point.
  • Get the image paths from a folder.
  • Traverse through the images.
  • Get a specific image and append it to the image collection of the document using Presentation.getImages().append() method.
  • Get the image width and height, and convert them to point.
  • Set the slide size of the presentation based on the image size using Presentation.getSlideSize().setSize() method.
  • Add a slide to the document using Presentation.getSlides().append() method.
  • Set the image as the background image of the slide using the methods under SlideBackground object.
  • Save the document to a PowerPoint file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.pdf.graphics.PdfGraphicsUnit;
import com.spire.presentation.pdf.graphics.PdfUnitConvertor;
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

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

public class CustomizeSlideSize {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Remove the default slide
        presentation.getSlides().removeAt(0);

        //Get image files from a folder
        File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
        File[] picFiles  = directoryPath.listFiles();

        //Create a PdfUnitConvertor object
        PdfUnitConvertor convertor = new PdfUnitConvertor();

        //Loop through the images
        for (int i = 0; i < picFiles.length; i++)
        {
            //Get a specific image
            String imageFile = picFiles[i].getAbsolutePath();

            //Append it to the image collection
            BufferedImage bufferedImage =  ImageIO.read(new FileInputStream(imageFile));
            IImageData imageData = presentation.getImages().append(bufferedImage);

            //Get image height and width in pixel
            int height = imageData.getHeight();
            int width = imageData.getWidth();

            //Convert pixel to point
            float widthPoint = convertor.convertUnits(width, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
            float heightPoint= convertor.convertUnits(height, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);

            //Set slide size
            presentation.getSlideSize().setSize(new Dimension((int)widthPoint, (int)heightPoint));

            //Add a slide
            ISlide slide = presentation.getSlides().append();

            //Set the image as the background image of the slide
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //Save to file
        presentation.saveToFile("output/CustomizeSlideSize.pptx", FileFormat.PPTX_2013);
    }
}

Java: Convert Images (PNG, JPG, BMP, etc.) to PowerPoint

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.

Published in Conversion
Thursday, 04 November 2021 05:19

Java: Convert ODP to PDF

The OpenDocument Presentation Document Format, commonly referred to as ODP, is one of the file extensions of an Open Document Format file and is designed to serve as an open-source display format for slideshow presentations. Sometimes you may need to convert an ODP file to PDF to ensure the document's formatting remains intact. In this article, you will learn how to achieve this function 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>11.10.4</version>
    </dependency>
</dependencies>

Convert ODP to PDF

You can convert ODP to PDF using Spire.Presentation for Java in an easy and quick manner by following the steps listed below.

  • Create a Presentation object.
  • Load a sample ODP document using Presentation.loadFromFile() method.
  • Save the document as PDF using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class ODPtoPDF {
    public static void main(String[] args) throws Exception {

        //Create a Presentation instance
        Presentation presentation = new Presentation();

        //Load a sample ODP file
        presentation.loadFromFile("toPDF.odp",FileFormat.ODP);
        
        //Save it as PDF
        presentation.saveToFile("output/Result.pdf", FileFormat.PDF);
    }
}

The original file:

Java: Convert ODP to PDF

The generated file:

Java: Convert ODP 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.

Published in Conversion
Monday, 31 July 2023 02:53

Java: Convert PowerPoint to HTML

PowerPoint to HTML conversion opens up opportunities for wider accessibility and enhanced interactivity. By transforming your presentations into HTML format, you can effortlessly distribute them across various platforms and devices. Whether you aim to share slides online or integrate them seamlessly within a web page, converting PowerPoint to HTML provides a flexible and versatile solution. In this article, we will explore how to convert PowerPoint files to HTML in Java using Spire.Presentation for Java.

Install Spire.Presentation for Java

First, 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>11.10.4</version>
    </dependency>
</dependencies>

Convert a PowerPoint Presentation to HTML in Java

With Spire.Presentation for Java, you can convert PowerPoint files to HTML format in just three steps. The detailed steps are as follows:

  • Initialize an instance of the Presentation class.
  • Load a sample PowerPoint document using Presentation.loadFromFile() method.
  • Save the PowerPoint presentation as HTML using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class ToHtml {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the sample document       presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

        //Save the document to HTML format       presentation.saveToFile("C:\\Users\\Administrator\\Desktop\\ToHtml.html", FileFormat.HTML);
        presentation.dispose();
   }
}

Java: Convert PowerPoint to HTML

Convert a Specific PowerPoint Slide to HTML in Java

Sometimes, it may be necessary to convert a single slide rather than the entire presentation to HTML. In such cases, Spire.Presentation for Java provides the ISlide.saveToFile() method for converting a PowerPoint slide to HTML format. The following are the detailed steps:

  • Initialize an instance of the Presentation class.
  • Load a sample PowerPoint document using Presentation.loadFromFile() method.
  • Get the specific slide using Presentation.getSlides().get() method.
  • Save the PowerPoint slide to HTML using ISlide.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.ISlide;

public class ConvertSpecificSlideToHtml { public static void main(String[] args) throws Exception {
    // Create a Presentation object
    Presentation presentation = new Presentation();

    // Load the sample document  presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

    // Get the specific slide by index (e.g., index 0 for the second slide)
    ISlide slide = presentation.getSlides().get(1);

    // Save the specific slide to HTML format  slide.saveToFile("C:\\Users\\Administrator\\Desktop\\SpecificSlideToHtml.html", FileFormat.HTML);
    slide.dispose();
   }
}

Java: Convert PowerPoint to HTML

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.

Published in Conversion
Monday, 26 September 2022 07:03

Java: Convert PowerPoint to XPS

XPS (XML Paper Specification) is a fixed-format document described by an XML-based language. It maintains a consistent appearance for documents, which is an ideal file format for publishing, archiving and transmitting. This article will demonstrate how to programmatically convert PowerPoint to XPS 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>11.10.4</version>
    </dependency>
</dependencies>

Convert PowerPoint to XPS

The detailed steps are as follows:

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.loadFromFile() method.
  • Save the PowerPoint document to XPS using Presentation.saveToFile(java.lang.String file, FileFormat fileFormat) method.
  • Java
import com.spire.presentation.*;

public class PowerPointtoXPS {
    public static void main(String[] args) throws Exception{

        //Create a Presentation instance
        Presentation ppt = new Presentation();

        //Load a sample PowerPoint file
        ppt.loadFromFile("E:\\Files\\test.pptx");

        //Save to XPS file
        ppt.saveToFile("toXPS.xps", FileFormat.XPS);
        ppt.dispose();
    }
}

Java: Convert PowerPoint to XPS

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.

Published in Conversion

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>11.10.4</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.

Published in Conversion

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>11.10.4</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<byte[]> 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.

Published in Conversion