Free Support Forum - aspose.com

How to extract all the text from a slide

I’m trying to extract all the text from a slide. I use the following code:

string result = string.Empty;
foreach( Aspose.Slides.Shape shape in slide.Shapes )
{
if( shape.TextFrame != null )
{
result += shape.TextFrame.Text;
}
}

However, result variable has only part of the text from a slide. Some of the text is missing. What should I do to get all the text?


PS: I’m trying to play with a presentation attached. While iterating through the first slide "“Layer 1 VPNs” and “61st IETF Washington …” texts are missing.

string result = string.Empty;
for(int j = 0; j < slide.Shapes.Count; j++)
{
Shape shape = slide.Shapes[j];
if (!shape.IsTextHolder && shape.TextFrame != null)
{
result += shape.TextFrame.Text;
}
}
for(int j = 0; j < slide.Placeholders.Count; j++)
{
TextHolder holder = slide.Placeholders[j] as TextHolder;
if (holder != null)
{
result += holder.Text;

}
}

Shouldn’t that first if check to see if the shape IS a TextHolder? Not the other way around?

If you need just read text then you can skip TextHolder checking.
But Text property will be always empty string for TextHolder shapes.