Aspose.Slides - Insert Auto Shapes in Presentation

//Get the first slide
ISlide sld = pres.getSlides().get_Item(0);

for (int i = 1 ; i <= ShapeType.ChartPlus ; i++)
{
	System.out.println(i + ". Done.");
	//Add an auto shape of type line
	sld.getShapes().addAutoShape(i, 50, 100, 150, 100);
	sld = pres.getSlides().addEmptySlide(pres.getLayoutSlides().get_Item(0));
}

Apache POI SL

//Line shape
Line line = new Line();
line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20));
line.setLineColor(new Color(0, 128, 0));
line.setLineStyle(Line.LINE_DOUBLE);
slide.addShape(line);

//TextBox
TextBox txt = new TextBox();
txt.setText("Hello, World!");
txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));

//use RichTextRun to work with the text format
RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
rt.setFontSize(32);
rt.setFontName("Arial");
rt.setBold(true);
rt.setItalic(true);
rt.setUnderlined(true);
rt.setFontColor(Color.red);
rt.setAlignment(TextBox.AlignRight);

slide.addShape(txt);

//Autoshape
//32-point star
AutoShape sh1 = new AutoShape(ShapeTypes.Star32);
sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
sh1.setFillColor(Color.red);
slide.addShape(sh1);

//Trapezoid
AutoShape sh2 = new AutoShape(ShapeTypes.Trapezoid);
sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200));
sh2.setFillColor(Color.blue);
slide.addShape(sh2);

Download Source Code

For More Examples, Please Visit Aspose Docs

Last edited Feb 12, 2015 at 5:12 PM by shoaibkhan, version 1