In certain cases, you may need to extract images from PowerPoint presentations along with the text. To achieve that, this article covers how to extract images from PowerPoint PPT or PPTX programmatically in Java. You will also learn how to extract images only from the backgrounds or the shapes in PPT slides.
- Java API to Extract Images from PowerPoint PPT
- Extract Images from a PPT in Java
- Extract Images from Shapes in PPTX
- Image Extraction from PPT Slide Background
Java API to Extract Images from PowerPoint PPT
Aspose.Slides for Java is a popular and feature-rich API that allows you to create and manipulate PowerPoint presentations seamlessly. We will use this API for extracting images from PPT/PPTX files. You can either download API’s JAR or install it using the following Maven configurations.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-slides</artifactId> <version>22.1</version> <classifier>jdk16</classifier> </dependency>
Extract Images from a PowerPoint PPT in Java
In PowerPoint presentations, all the images used in the slides are stored in an image collection. This collection can be accessed and each image can be saved as a file. The following are the steps to extract all the images in a PPT presentation in Java.
- First, use Presentation class to load the PPT/PPTX presentation.
- Then, access the image collection in the presentation using Presentation.getImages() method.
- Finally, get type and format of each image and save it.
The following code sample shows how to extract images from a PowerPoint PPTX file in Java.
Extract Images from PPTX Shapes in Java
You can also extract images only from the shapes in the PPT slides. The following are the steps to accomplish that.
- First, use Presentation class to load the presentation file.
- Then, use Presentation.getSlides() method to access slides collection.
- For each slide, access its shapes using ISlide.getShapes() method.
- Perform the following steps for each shape in the collection:
The following code sample shows how to extract images from shapes in a PPT using Java.
Java Image Extraction from PPT Slide Backgrounds
Another possible scenario could be extracting images that are used only as slide backgrounds. The following steps show how to extract slide background images in Java.
First, load the presentation using Presentation class.
Then, loop through the slides in the presentation using Presentation.getSlides() method.
For each slide, perform the following steps:
Check if slide has a background image using ISlide.getBackground().getFillFormat().getFillType() method.
If the background has picture then extract image using getImage() method.
Check if the layout slide has background image using ISlide.getLayoutSlide().getBackground().getFillFormat().getFillType() method.
If layout slide’s background is filled with a picture then extract it using getImage() method.
Finally, save the extracted image as a file.
The following code sample shows how to extract images from slide backgrounds in a PPT in Java.
Java PowerPoint Image Extraction API - Get a Free License
Aspose offers a free temporary license to use Aspose.Slides for Java without evaluation limitations. You can get one for yourself.
In this article, we have demonstrated how to extract images from PowerPoint PPT/PPTX in Java. In addition, we have covered how to extract images either from the shape or slide backgrounds separately. Besides, you can read more about Aspose.Slides for Java by visiting the documentation. Also, you can post your queries to our forum.