Finding header of a new slide

Hi,

I’m trying to evaluate aspose.slides product for a customer’s requirement. I need to create a ppt on the fly, so there is no reference to an existing ppt.

I’m tryoing to create a new presentation and adding a body slide. Got the reference of this slide and and able to iterate through all the shapes present in it. How will I able to get the exact shape of the header and body placeholders??

I tried MetaCharacters, but it returns null. Is there an explicit attribute to determine the shape? Below is the code.

Presentation pres = new Presentation();
Slide slide;

pres.AddBodySlide();
slide = pres.GetSlideByPosition(2);
slide.HeaderFooter.IsPageNumberVisible = true;
slide.HeaderFooter.IsFooterVisible = true;
slide.HeaderFooter.FooterText = "Created on " + DateTime.Now.ToShortDateString();

for (int i = 0; i < slide.Shapes.Count; i++)
{
Shape sh = slide.Shapes[i];
if (sh.TextFrame != null)
{
if (sh.TextFrame.MetaCharacters != null && sh.TextFrame.MetaCharacters.Count > 0 && sh.TextFrame.MetaCharacters[0] == MetaCharacterType.Header)
{
Portion portionHeader = sh.TextFrame.Paragraphs[0].Portions[0];
portionHeader.Text = “Could make it this far!!”;
break;
}
}
}

Hi Sarath,

Thanks for your interest in Aspose.Slides.

I regret to inform you that there is no explicit way to identify that whether a shape is a title or body place holder. Please use the following code snippet for extracting only place holders in the slide and excluding rest of shapes. Usually the first text holder is Title and second text holder is Body type.

Presentation Pres = new Presentation("D:\\ppt\\asd.ppt");

Slide Sld = Pres.Slides[0];

foreach(Aspose.Slides.Shape Shp in Sld.Shapes)

{

if (Shp.IsTextHolder)

{

TextFrame TxtFrm = Shp.TextFrame;

Console.WriteLine(TxtFrm.Text);

}

}

Thanks and Regards,

That was helpful. As I’ve said, I need to create a powerpoint on the fly (dynamic). I don’t have a reference to an existing power point like

Presentation Pres =
new Presentation(“D:\ppt\asd.ppt”);


So, when i create a new presentation and add a BodySlide, how can I use it?

Presentation pres = new Presentation();
Slide slide = pres.AddBodySlide();

Now the reference to this slide has no paragraphs. So, I’m unable to add any text to which is what I need.

Alternatively, I created a empty slide and added rectangles to it. So, that its forming a header and body placeholder. Now the body placeholder is a big rectangle. Depending on the length of the text content inserted, it is aligning to the middle of the slide.

Could you please let me know if there is a way to create all this without using a existing powerpoint reference??


thanks

Sarath

Hi Sarath,

I have written some code snippet for you again. Hopefully it will help you. Please use the code snippet given below for identifying Title and Body shapes and adding text to them.

Presentation Pres = new Presentation();

Slide Sld = Pres.AddBodySlide();

foreach(Aspose.Slides.Shape Shp in Sld.Shapes)

{

if (Shp.IsTextHolder)

{

TextHolder TxtFrm = Shp.Placeholder as TextHolder;

String sPalceholderType = Shp.Placeholder.PlaceholderType.ToString();

if(sPalceholderType=="CenteredTitle1")

{

Paragraph pPara = new Paragraph();

TxtFrm.Paragraphs.Add(pPara);

Portion pPortion = new Portion("Title Text");

pPara.Portions.Add(pPortion);

}

else if (sPalceholderType == "Body")

{

Paragraph pPara = new Paragraph();

TxtFrm.Paragraphs.Add(pPara);

Portion pPortion = new Portion("Aspose.Slides");

pPara.Portions.Add(pPortion);

}

}

}

Pres.Write("D:\\test.ppt");

Thanks and Regards,