// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();

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

//Add an AutoShape of Rectangle type
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);

//Add ITextFrame to the Rectangle
ashp.addTextFrame("Hello World");


// Where will we save our new .ppxt?
String outputfilepath = dataPath + "Pptx4jHelloWorld.pptx";
if (MACRO_ENABLE) outputfilepath += "m";

// Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage(); 

	ContentTypeManager ctm = presentationMLPackage.getContentTypeManager();
	ctm.removeContentType(new PartName("/ppt/presentation.xml") );
	ctm.addOverrideContentType(new URI("/ppt/presentation.xml"), ContentTypes.PRESENTATIONML_MACROENABLED);
// Need references to these parts to create a slide
// Please note that these parts *already exist* - they are
// created by createPackage() above.  See that method
// for instruction on how to create and add a part.
MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
		new PartName("/ppt/presentation.xml"));		
SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
		new PartName("/ppt/slideLayouts/slideLayout1.xml"));

// OK, now we can create a slide
SlidePart slidePart = new SlidePart(new PartName("/ppt/slides/slide1.xml"));
slidePart.setContents( SlidePart.createSld() );		
pp.addSlide(0, slidePart);

// Slide layout part

// Create and add shape
Shape sample = ((Shape)XmlUtils.unmarshalString(SAMPLE_SHAPE, Context.jcPML) );

Download Source Code

For More Examples, Please Visit Aspose Docs

Last edited Feb 6, 2015 at 10:05 AM by shoaibkhan, version 1