Drawing Shapes using POI
Previous | Home | Next |
In this page of the example we are going to create auto shape on PowerPoint slide using java. In this program, we are going to create 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 usingsetFillColr(Color col) method.
Firstly we are going to create 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 usingsetFillColr(Color col) method.
package r4r; 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; public class createautoshape { public static void main(String a[]) { try { SlideShow Show = new SlideShow(); Slide slide1 = Show.createSlide(); AutoShape as = new AutoShape(ShapeTypes.Star32); as.setAnchor(new java.awt.Rectangle(0, 0, 500, 500)); as.setFillColor(Color.DARK_GRAY); AutoShape as1 = new AutoShape(ShapeTypes.Star32); as1.setAnchor(new java.awt.Rectangle(200, 200, 200, 200)); as1.setFillColor(Color.green); AutoShape as2 = new AutoShape(ShapeTypes.Star32); as2.setAnchor(new java.awt.Rectangle(150, 150, 300, 300)); as2.setFillColor(Color.BLUE); AutoShape as3 = new AutoShape(ShapeTypes.Star32); as3.setAnchor(new java.awt.Rectangle(100, 100, 400, 400)); as3.setFillColor(Color.gray); slide1.addShape(as); slide1.addShape(as3); slide1.addShape(as2); slide1.addShape(as1); FileOutputStream fos = new FileOutputStream("autoShape.ppt"); Show.write(fos); fos.close(); }catch(Exception e){} } }
Previous | Home | Next |