Change Background of Slide Using Java

In this example we are going to create a slide then change background of the
slide.
In this example we are creating an object of the shape. In this object we assign
rectangle shape and set the size and position. Initial values for x and y axis
are 0.The height and width are 800 and 600 respectively. Then create
an object of Shape and set values, fill type, background color
and foreground color of the slide. Then finally add into slide. We are
using setFillType(Fill.FILL_SHADE) method to set fill
type, setBackgroundColor(Color.blue) method to set background
color and setForegroundColor(Color.green) method
to set the text color.
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 changeBackground
{
public static void main(String a[])
{
try
{
SlideShow slideShow = new SlideShow();
Slide slide = slideShow.createSlide();
Shape shape = new AutoShape(ShapeTypes.Rectangle);
shape.setAnchor(new java.awt.Rectangle(0, 0, 800, 660));
Fill fill = shape.getFill();
fill.setFillType(Fill.FILL_SHADE);
fill.setBackgroundColor(Color.blue);
fill.setForegroundColor(Color.green);
slide.addShape(shape);
FileOutputStream out = new FileOutputStream
("changeBackground.ppt");
slideShow.write(out);
out.close();
}catch(Exception e){}
}}
|
The output of the program is given below:

Download this example.

|
Current Comments
0 comments so far (post your own) View All Comments Latest 10 Comments: