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

Free Support Forum - aspose.com

Updating from vers. 3.0.1.15296 to 3.1.0.0 broke my code

After adding a reference to 3.1.0.0 in my Referenced DLLs folder, I got the following error (needless to say, my project was compiling before I did this):

Error 1 ‘Aspose.Slides.Pptx.ShapeEx’ does not contain a definition for ‘TextFrame’ and no extension method ‘TextFrame’ accepting a first argument of type ‘Aspose.Slides.Pptx.ShapeEx’ could be found (are you missing a using directive or an assembly reference?) C:…\Documents\Visual Studio 2008\Projects\PPPowerpointProcessingService\PPPowerpointProcessing.BusinessLogic\PowerpointManager.cs 123 16 PPPowerpointProcessing.BusinessLogic

What’s with the TextFrame? Has this been removed from the DLL, or am I doing something wrong by simply replacing the old DLL with the new?

Any help on this matter would be greatly appreciated.

Sorry.
In pptx format only autoshapes and table cells can contain textframes. Adding TextFrame property to base class ShapeEx was an error. We’ve moved this property to AutoShapeEx class to make API less misleading.

Hi,

My code also broke with the API change. I need to extract text from pptx files. I have been using the recommend approach as a guide, but some of the objects aren’t there any more (eg, TextHolderEx doesn’t exist)

Can you please let me know how to extract all of the text from a pptx file?

Thanks,
Brian.

Hello Brian,

What API change you mean? We never had TextHolderEx class. Ppt and Pptx presentations have different set of features so it is obvious that Pptx namespace should have new improved API structure. For simple text extraction from pptx file you can use next code:

PresentationEx pres = new PresentationEx(“a.pptx”);
for (int i = 0; i < pres.Slides.Count; i++)
{
SlideEx slide = pres.Slides[i];
int shapesCount = sld.Shapes.Count;
for (int shpIdx = 0; shpIdx < shapesCount; shpIdx++)
{
AutoShapeEx shp = sld.Shapes[shpIdx] as AutoShapeEx;
if (shp != null && shp.TextFrame != null)
{
ParagraphsEx paras = shp.TextFrame.Paragraphs;
if (paras != null)
{
int parasCount = paras.Count;
for (int paraIdx = 0; paraIdx < parasCount; paraIdx++)
{
ParagraphEx para = paras[paraIdx];
Console.WriteLine(para.Text);
}
}
}
}
}

This code works similar to “recommened approach”. To make full text extraction you need also iterate grouped shapes and table cells.

alcrus:

What API change you mean? We never had TextHolderEx class.


Oops, I meant that the ShapeEx.TextFrame property was removed. I understand that it was a mistake for it to be there in the first place. Even so, it might be a good idea to put it in the release notes

alcrus:

Ppt and Pptx presentations have different set of features so it is obvious that Pptx namespace should have new improved API structure. For simple text extraction from pptx file you can use next code:


No! This is not obvious. I don't know much about PowerPoint, and I don't know anything about the new features added by pptx. All I need to do is extract the text. I think it would help a lot of people (including you guys) if you'd add a method to the API to extract the text.

alcrus:

To make full text extraction you need also iterate grouped shapes and table cells.


How do I do this? Can you provide the full code for extract all text from a pptx?

Hello Brian,

There is code to extract all text from a pptx presentation with recursion to iterate nested group shapes and tables. We will add this code to the documentation.


private void PrintText(ParagraphsEx paras)
{
if (paras != null)
foreach (ParagraphEx para in paras)
Console.WriteLine(para.Text);
}

private void IterateShapes(ShapesEx shapes)
{
foreach (ShapeEx shape in shapes)
{
if (shape is AutoShapeEx)
{
AutoShapeEx autoShp = (AutoShapeEx)shape;
if (autoShp.TextFrame != null)
PrintText(autoShp.TextFrame.Paragraphs);
}
else if (shape is GroupShapeEx)
{
IterateShapes(((GroupShapeEx)shape).Shapes);
}
else if (shape is TableEx)
{
TableEx table = (TableEx) shape;
foreach (RowEx row in table.Rows)
{
foreach (CellEx cell in row)
{
if (cell.TextFrame != null)
PrintText(cell.TextFrame.Paragraphs);
}
}
}
}
}

public void TextExtract()
{
PresentationEx pres = new PresentationEx("a.pptx");
foreach (SlideEx slide in pres.Slides)
IterateShapes(slide.Shapes);
}