Creating Auto Shape in PowerPoint Using Java

In this example we are going to create auto shape on PowerPoint slide using java.

Creating Auto Shape in PowerPoint Using Java

In this example we are going to create auto shape on PowerPoint slide using java.

Creating Auto Shape in PowerPoint Using Java

Creating Auto Shape in PowerPoint Using Java

     


In this example we are going to create auto shape on PowerPoint slide using java.

In this example, we are creating the object of AutoShape .We are passing the shape type into AutoShape as argument parameter .We are passing ShapeTypes.Star32 as shape type. Then we are using setAnchor() method to give the position of the shape. To fill the color we are using setFillColr(Color colr)  method.
  
 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.model.*;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.usermodel.*;
import java.io.*;
import java.awt.*;
import org.apache.poi.hslf.model.TextBox;
class autoShape
{
  public static void main(String a[])
  {
  try
  SlideShow slideShow = new SlideShow();
 Slide slide = slideShow.createSlide();
 AutoShape sh1 = new AutoShape(ShapeTypes.Star32);
 sh1.setAnchor(new java.awt.Rectangle
(
00600600));
 sh1.setFillColor(Color.red);
 AutoShape sh2 = new AutoShape(ShapeTypes.Star32);
 sh2.setAnchor(new java.awt.Rectangle
(
200200200200));
 sh2.setFillColor(Color.green);
  AutoShape sh3 = new AutoShape(ShapeTypes.Star32);
 sh3.setAnchor(new java.awt.Rectangle
(
150150300300));
 sh3.setFillColor(Color.red);
  AutoShape sh4 = new AutoShape(ShapeTypes.Star32);
 sh4.setAnchor(new java.awt.Rectangle
(
100100400400));
 sh4.setFillColor(Color.green);
 slide.addShape(sh1);
 slide.addShape(sh4);
     slide.addShape(sh3);
     slide.addShape(sh2);
  FileOutputStream out = new FileOutputStream
(
"autoShape.ppt");
  slideShow.write(out);
  out.close();
  }catch(Exception e){}
  }}

The output of the program is given below:

Download this example.