Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

How to merge two PPTs using Java



Problem Description

How to merge two PPTs using Java.

Solution

Following is the program to merge two PPTs using java.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class MergingMultiplePresentations {
   public static void main(String args[]) throws IOException {

      //creating empty presentation
      XMLSlideShow ppt = new XMLSlideShow();

      //taking the two presentations that are to be merged
      String file1 = "C:/poippt/presentation1.pptx";
      String file2 = "C:/poippt/presentation2.pptx";
      String[] inputs = {file1, file2};

      for(String arg : inputs) {
         FileInputStream inputstream = new FileInputStream(arg);
         XMLSlideShow src = new XMLSlideShow(inputstream);

         for(XSLFSlide srcSlide : src.getSlides()){

            //merging the contents
            ppt.createSlide().importContent(srcSlide);
         }
      } 
      String file3 = "C:/poippt/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();
   }
} 

Input

Merge PPT

 

Merge Input

Output

Merge Output
java_apache_poi_ppt
Advertisements