Apache POI PPT Tutorial
Selected Reading
- Apache POI PPT - Discussion
- Apache POI PPT - Useful Resources
- Apache POI PPT - Quick Guide
- Apache POI PPT - PPT to Image
- Apache POI PPT - Merging
- Apache POI PPT - Formatting Text
- Apache POI PPT - Reading Shapes
- Apache POI PPT - Creating Hyperlinks
- Apache POI PPT - Images
- Apache POI PPT - Slide Management
- Apache POI PPT - Slide Layouts
- Apache POI PPT - Presentation
- Apache POI PPT - Classes & Methods
- Apache POI PPT - Installation
- Apache POI PPT - Java API Flavors
- Apache POI PPT - Overview
- Apache POI PPT - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache POI PPT - Merging
Apache POI PPT - Merging
You can merge multiple presentations using the importContent() method of the XMLSpdeShow class. Given below is the complete program to merge two presentations −
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xslf.usermodel.XMLSpdeShow; import org.apache.poi.xslf.usermodel.XSLFSpde; pubpc class MergingMultiplePresentations { pubpc static void main(String args[]) throws IOException { //creating empty presentation XMLSpdeShow ppt = new XMLSpdeShow(); //taking the two presentations that are to be merged String file1 = "presentation1.pptx"; String file2 = "presentation2.pptx"; String[] inputs = {file1, file2}; for(String arg : inputs){ FileInputStream inputstream = new FileInputStream(arg); XMLSpdeShow src = new XMLSpdeShow(inputstream); for(XSLFSpde srcSpde : src.getSpdes()) { //merging the contents ppt.createSpde().importContent(srcSpde); } } String file3 = "combinedpresentation.pptx"; //creating the file object FileOutputStream out = new FileOutputStream(file3); // saving the changes to a file ppt.write(out); System.out.println("Merging done successfully"); out.close(); } }
Save the above code as MergingMultiplePresentations.java, and then compile and execute it from the command prompt as follows −
$javac MergingMultiplePresentations.java $java MergingMultiplePresentations
It will compile and execute to generate the following output −
Merging done successfully
The following snapshot shows the first presentation −
The following snapshot shows the second presentation −
Given below is the output of the program after merging the two spdes. Here you can see the content of the earper spdes merged together.
Advertisements