Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Poi Change Background Picture of Slide Using Java

Related Tutorials


 
 

Share on Google+Share on Google+

Change Background Picture of Slide Using Java

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

Change Background Picture of Slide Using Java  

     


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

In this example we are creating a slide. In this slide we are inserting a picture to set this picture as background. To set picture as background of slide we are using setPictureData(nameofpicture ) method. We are setting the  pattern type of the picture. To set the pattern we are using setFillType(filltype) method. 

addPicture(byte[] pictureData,int format):
This method is used to add a picture to the workbook. The return type of this method is int. The two parameters are passed into this method. The first one is pictureData and second one is format .The pictureData is byte form of the picture. In this example we are using Picture.PNG as format.

setPictureData(byte[] pictureData):
This method is used to set the picture. Here picture data is name of picture in byte format.

 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 slideBackgroundShap
{
  public static void main(String a[])
  {
  try
  {  
  SlideShow slideShow = new SlideShow();
  Slide slide = slideShow.createSlide();
  slide.setFollowMasterBackground(false);
  Fill fill = slide.getBackground().getFill();
  int id = slideShow.addPicture(new File
(
"1.png"), Picture.PNG);
  fill.setFillType(Fill.FILL_PATTERN);
  fill.setPictureData(id);
  FileOutputStream out = new FileOutputStream
(
"slideBackground.ppt");
  slideShow.write(out);
  out.close()
  }catch(Exception e){}
  }}

The output of the program is given below:

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 14, 2008

Related Tutorials

Discuss: Change Background Picture of Slide Using Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com