POI

POI api Projects

POI api Project 1

Change Background of Master Slide
Previous Home Next

In this page of the tutorials we are going to create a slide then we try to change the background of the master slide. In this example firstly we are going to creating a master slide for the slide show.

To create slide show we are using SlideShow constructor and to create master slide we are using SlideMaster constructor.After the creation of the masterslide we are going to create the fill. this is used for setting background and for adding a picture.

Then We are using getFill() method to create the fill object. The setFillType(type) is used allow to set the type of fill. In this program, we are using picture type. Finally we are adding the picture into master slide in fill.

Example

package r4r;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.model.*;
import java.io.*;
import java.awt.Color;
import org.apache.poi.hslf.model.TextBox;
public class changebgofmasterslide {
	public static void main(String a[])
	  {
	  try
	  {  
	  SlideShow slideShow = new SlideShow();
	  SlideMaster master = slideShow.getSlidesMasters()[0];
	  Fill fill = master.getBackground().getFill();
	  int id = slideShow.addPicture(new File("2.png"),
	 Picture.PNG);
	  fill.setFillType(fill.FILL_PICTURE);
	  fill.setPictureData(id);
	  FileOutputStream out = new FileOutputStream
	("Backgroundpresentation.ppt");
	  slideShow.write(out);
	  out.close(); 
	  }catch(Exception e){}
	  }
}
Previous Home Next