Home Java Poi Change Background of Master Slide Using Java



Change Background of Master Slide Using Java
Posted on: March 14, 2008 at 12:00 AM
In this example we are going to create a slide then change background of the master slide.

Change Background of Master Slide Using Java  

     


In this example we are going to create a slide then change background of the master slide.

In this example we are creating a slide master for the slide show. To create slide show we are using SlideShow constructor and to create master slide we are using SlideMaster constructor. Then we are creating fill for setting background and for adding a picture. We are using getFill() to create the fill object. The setFillType(type) is used to set the type of fill. In this example, we are using picture type. Finally we are adding the picture into master slide in fill.
  
 The code of the program is given below:
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;
class MasterSlideBackground
{
  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
(
"MasterBackground.ppt");
  slideShow.write(out);
  out.close()
  }catch(Exception e){}
  }}

The output of the program is given below:

Download this example.

Related Tags for Change Background of Master Slide Using Java:
cideconstructorobjectstructsedbackgroundgettypeconstchangeusingintthisidsetcreateshowforexamplefinaladdpictureslideshowtoroundexamfinallymasterpicastsheilslidebackfilldeslihangusepeinaddinaddingasmnttrddjadesemallpihowintoobjackcreatingtorxaxampsctoratkishallmplgoeaandarconsstrtfsettingslittssthshostatictofinjepleplndono


More Tutorials from this section

Ask Questions?    Discuss: Change Background of Master Slide Using Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.