How to generate Diamond autoshape in java by using Aspose

Hi Guys,

I am trying to generate one Diamond shape can u please help me how to get Autoshapes in aspose for PPT slides.

Thanks & Regards

Dear Setu,

Thanks for considering Aspose.Slides.

Diamond shape is an AutoShape. You can copy any autoshape from other slides or presentation into your slide using serialization.

Access your shape, serialize it and then add it in your slide’s shapes using Slide.Shapes.Add method.

e.g the code below get the shape from sourceSlide and copy it to destinationSlide.

C #

Shape shp1 = sourceSlide.Shapes[0];

MemoryStream ms = new MemoryStream();
ms.Position = 0;

//Copy the serialized shape to destination slide

You need to do the same thing in JAVA, serialize the shape and then add it.

Here is a complete code that illustrates in JAVA, how to serialize any non-group shape into stream and then add into the shapes collection of another slide from that stream.

Please see the source and output presentation from the attachment.



//Read the source presentation

Presentation pres = new Presentation(new FileInputStream("c:\\source.ppt"));

//Access the slides

Slide slide=pres.getSlideByPosition(1);

Slide slide2=pres.getSlideByPosition(2);

//Get the diamond shape

Shape shp=slide.getShapes().get(0);

//Serialize the shape

byte[] buf=null;

ByteArrayOutputStream bis=new ByteArrayOutputStream();


//Add the shape into slide2


ByteArrayInputStream bin=new ByteArrayInputStream(buf);


pres.write(new FileOutputStream("c:\\output.ppt"));