How to add predefiend shapes in ppt

hi,

in ppt when we select any textframe, at the top we can see something called drawing tools being highligted.

under this we have a tab called Format.

when we select this tab at the top left corner we can see a section(Insert Shapes) containing some shapes, how can i add them programatically?

please share your tips on this........

Regards,

Raghavendra.

Hello,

Currently there is no direct way to insert such shapes but workaround exists.
1. Create some template presentation and add necessary AutoShapes to a slide.
2. Using Aspose.Slides serialize these autoshapes to binary files.
3. Add these files as resources to your application or simply put it together with app binaries.
4. Now you can add shapes to a generated presentation from stream/file using Shapes.Add(Stream) method.

hi Alexey Zhilin,

thanks for that information, can you please share some sample as to how this can be achieved.

Thanks and Regards,
Raghavendra

Hello,

You will find code example in this thread. Please write if you need some additional information.

Example was in Java. There is the same example converted to C#:

Slide slide = …;
Shapes.shapes = slide.Shapes;

for (int i = 0; i < shapes.Count; i++) {
Shape sh = shapes[i];
sh.serialize(new FileStream(…));
}



Slide slide = …;
Shapes shapes = slide.Shapes;

Shape shape = shapes.Add(new FileStream(…));
// Move and resize created autoshape.
shape.X = 0;
shape.Y = 0;
shape.Width = 1000;
shape.Height = 2000;

hi alcrus,

i have followed as mentioned above, but facing porblem.

i am not able to get any shapes when i say

Presentation presentation = new Presentation("temp.ppt");

Slide s = presentation.AddEmptySlide();

Aspose.Slides.Shapes shapes = s.Shapes;

MemoryStream ms = new MemoryStream();
for (int i = 0; i < shapes.Count; i++)
{
Aspose.Slides.Shape sh = shapes[i];
//Serialize the shape
sh.Serialize(ms);
}
if (ms.Length > 0)
{
Aspose.Slides.Shape newShape = s.Shapes.Add(ms);

newShape.X = 10;
newShape.Y = 10;
newShape.Width = 1000;
newShape.Height = 2000;
}

when i try to execute the code i am getting the value of "shapes.Count" as zero.

in the template ppt i have added the shape.

can you help me in this........?

Thanks,

Raghavendra

Hello,

You should set MemoryStream.Position to 0 before adding a serialized shape.

hi alcrus,

when i say

Presentation presentation = new Presentation("temp.ppt");

Slide s = presentation.AddEmptySlide();

Aspose.Slides.Shapes shapes = s.Shapes;

after the above statement is excecuted the

s.Shapes.Count is zero(0).

which means there are no symbols in the slide.

but i have placed 5 symbols in the slide.

can you please tell me where i am going wrong?

Regards,

Raghavendra.

Hello,

I didn’t check your code carefully.

You create empty slide (without shapes!) and try to serialize these 0 shapes to a stream. As a result your stream is empty. You should create presentation in PowerPoint with all necessary autoshapes and serialize them. After that you can create new slides, load autoshapes from the stream and insert it to the new slide.

One more problem is each autoshape should be serialized to a separate stream. If you serialize everything to a one stream and try to read it back then it won’t work.

hi,

in my senario i will be having a template presentation where i will be having a template slide.

now if i add the template slide some shapes and use them it is not going to work for me.

for reasons below

1. first of all.. my slides will be of different chart types. so i need that shape only for a specific chart type say bar.

2. if i put that shape in the template slide and use that then as soon as the first slide is generated (say a radar type) the shape will be gone from the template slide(i think so...).

3. from second slide on... the template slide will be empty (no shapes).so for me to continue with generation of charts i have been adding an empty template.

know how can i add a shape for a bar type chart that is say a 3rd and 5th slide in my ppt.?

Regards,

Raghavendra.

Hello,

You can have separate small template presentation for autoshapes only and another one for slides with charts or with something else.

hi alcrus,

thanks for those inputs., i got what i needed.

Regards,
Raghavendra.