We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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
Setu

Dear Setu,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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();

shp1.Serialize(ms);

ms.Position=0;

//Copy the serialized shape to destination slide

destinationSlide.Shapes.Add(ms);

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.

JAVA

---------------------------------------------------------------------------------------------------

//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();

shp.serialize(bis);

//Add the shape into slide2

buf=bis.toByteArray();

ByteArrayInputStream bin=new ByteArrayInputStream(buf);

slide2.getShapes().add(bin);

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

---------------------------------------------------------------------------------------------------