Free Support Forum - aspose.com

Get all strings from slide

hello is there any way to take all string from presentation’s slide all mean it is in groups shape or in place holder or in textframe any.

If I’m not mistaken I repeated it several times yesterday in the IM conversation.
There is no one method call to do it.

Here is a method that I’ve been using to get all the text from a Slide



public static string GetSlideText(Slide source)
{
StringBuilder keywords = new StringBuilder();

if(source.Notes != null)
{
keywords.Append(source.Notes.Text);
keywords.Append(" “);
}
keywords.Append(source.HeaderFooter.HeaderText);
keywords.Append(” “);
keywords.Append(source.HeaderFooter.FooterText);
keywords.Append(” “);
keywords.Append(source.HeaderFooter.DateTimeText);
keywords.Append(” “);
foreach(Shape sh in source.Shapes)
{
keywords.Append(sh.AlternativeText);
keywords.Append(” “);
if(sh is Table)
{
Table tb = (Table) sh;
for(int tx = 0; tx < tb.ColumnsNumber; tx++)
{
for(int ty = 0; ty < tb.RowsNumber; ty++)
{
keywords.Append(tb.GetCell(tx, ty).TextFrame.Text);
keywords.Append(” “);
}
}
}
else if(sh is AutoShape)
{
AutoShape autoS = (AutoShape) sh;
if(autoS.TextFrame != null && autoS.TextFrame.Text != null)
{
keywords.Append(autoS.TextFrame.Text);
keywords.Append(” “);
}
}
else if(sh is Rectangle && sh.TextFrame != null && sh.Placeholder == null)
{
keywords.Append(sh.TextFrame.Text);
}
if(sh.Placeholder != null)
{
TextHolder th = sh.Placeholder as TextHolder;
if(th != null)
{
keywords.Append(th.Text);
}
}
}
string result = keywords.ToString();

// change everything that is not a letter or number or a white space into a space
result = Regex.Replace(result, @”[^a-zA-Z0-9\s]", " “);
// collapse multiple white spaces
result = Regex.Replace(result, @”\s+", " ");
result = result.Trim();

return result;
}