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

Free Support Forum - aspose.com

Is there a way to copy a layout as it is in a new slide?

When I make a layout with tables and rectangles (shapes in general) and I generate a new slide based on this layout, the displayed shapes are not editable on this slide (I tested this in PowerPoint but I think Aspose does the same). Is there a way to have them editable on the slide as they are in the slide master view ?

I have thought of copying those shapes, from the layout to the slide, but I think there’s no existing Aspose code to do this and there are too many properties that I have to copy by myself.

(Basically, I need to do this because --as far as I’ve seen-- the normal placeholders for text don’t allow you to specify multiple fonts and styles for their inner text, unlike shapes like rectangles.)

Thanks Kostas.

Hi Kostas,


I have observed your requirement and like to share that you right in your point that inherited layout shapes are not editable in normal slides but only editable in their respective layout slide. This also makes sense as well that layout slide is shared between multiple slides.

The available solution is to generate a slide with shapes similar to those available in layout slide. Then you will be able to change them as they will belong to local slide. Below please find the sample code that you may use as a satrarter and implement on your end to serve your needs. I have only generated shapes by copying the positions and size. You may also need set some other properties like fill type, fill colors from source shape to newly generated target shape. I hope this will give you a basis structure to get thing started and you may do the rest on your end for this.

public static void CopyPlaceHolder(String file, string path)
{
// PresentationEx presentation = new PresentationEx(“placeholdersTemplate.pptx”);
PresentationEx presentation = new PresentationEx(path+file);
presentation.UpdateDateTimeFields = true;
foreach (LayoutSlideEx layout in presentation.Masters[0].LayoutSlides)
{
presentation.Slides.AddEmptySlide(layout);
SlideEx slide = presentation.Slides[presentation.Slides.Count - 1];
foreach (ShapeEx shape in slide.LayoutSlide.Shapes)
{
if (shape.Placeholder != null)
{
switch (shape.Placeholder.Type)
{
default:
slide.Shapes.AddAutoShape(
ShapeTypeEx.RoundCornerRectangle, float.NaN, float.NaN, float.NaN, float.NaN);
break;
case PlaceholderTypeEx.SlideNumber:
{
slide.Shapes.AddAutoShape(
ShapeTypeEx.RoundCornerRectangle, float.NaN, float.NaN, float.NaN, float.NaN);
AutoShapeEx ashape = (AutoShapeEx)slide.Shapes[slide.Shapes.Count - 1];
ashape.AddTextFrame(“text”);
ashape.TextFrame.Paragraphs[0].Portions[0].AddField(FieldTypeEx.SlideNumber);
}
break;
case PlaceholderTypeEx.DateAndTime:
{
slide.Shapes.AddAutoShape(
ShapeTypeEx.RoundCornerRectangle, float.NaN, float.NaN, float.NaN, float.NaN);
AutoShapeEx ashape = (AutoShapeEx)slide.Shapes[slide.Shapes.Count - 1];
ashape.AddTextFrame(“text”);
ashape.TextFrame.Paragraphs[0].Portions[0].AddField(FieldTypeEx.DateTime);
}
break;
case PlaceholderTypeEx.Object:
case PlaceholderTypeEx.Table:
slide.Shapes.AddTable(
float.NaN, float.NaN, new double[] { 30, 30, 30 }, new double[] { 20, 20 });
break;
case PlaceholderTypeEx.Picture:
slide.Shapes.AddPictureFrame(
ShapeTypeEx.Ellipse, float.NaN, float.NaN, float.NaN, float.NaN, null);
break;
case PlaceholderTypeEx.Chart:
slide.Shapes.AddChart(
Aspose.Slides.Pptx.Charts.ChartTypeEx.StackedLine,
float.NaN,
float.NaN,
float.NaN,
float.NaN);
break;
//case PlaceholderTypeEx.Diagram:
// // TODO: add diagram insertion here
// break;
case PlaceholderTypeEx.Media:
slide.Shapes.AddVideoFrame(float.NaN, float.NaN, float.NaN, float.NaN, @“video.avi”);
break;
}
ShapeEx newShape = slide.Shapes[slide.Shapes.Count - 1];
newShape.AddPlaceholder(shape.Placeholder);
}
}
}
// presentation.Save(“placeholders.pptx”, SaveFormat.Pptx);
presentation.Save(path+file+“Copied.pptx”, SaveFormat.Pptx);


}


Many Thanks,

But then I will have to recreate the shape as it was myself and copy all of its styling.

I was trying to avoid that, but I guess there’s not another alternative…
It would be nice it there was a way to copy shapes exactly as they are from slide to slide and from layout to slide.

Anyway, thanks!

Hi Kostas,


Yes you need to create the new shape. Secondly, we are working over merged Aspose.Slides for .Net Api for PPT/PPTX, which is scheduled for delivery by end of this year or early next year. The said Api will hopefully involve the feature support for copying shapes and you will be able to use the feature on your end by then. For the time being, I have shared the possible solution with you.

Many Thanks,