Checking if a table has an image inside it

Good morning,

I’m working with the VB implementation, and currently has some code to check whether tables are empty and if so we remove them, this was originally worked on by a colleague in 2013 (discussed with you here: Hidden text in save as PDF and page count), this has worked great until recently when it became apparent that if there is an image but no text within the table that If oTable.ToString(SaveFormat.Text).Trim() returns as empty and so the table is removed.

I’m currently considering whether the other SaveFormat options would be usable, but I was hoping you might know of a quick way to check if a table also contains an image?

For reference the code loop is:

Dim oWord As Aspose.Words.Document
Dim oTable As Tables.Table

For Each oTable In oWord.GetChildNodes(NodeType.Table, True)
    If oTable.ToString(SaveFormat.Text).Trim() = "" Then
        oTable.Remove()
        'Trace(GetThisProcName(), "- hidden table in main document removed")
    End If
Next

Thank you and kind regards,

Stan

Hi Stan,

Thanks for your inquiry. Images in Aspose.Words are represented by Shape nodes. You can use the following code to detect which tables have images in it.

For Each oTable In doc.GetChildNodes(NodeType.Table, True)
    If oTable.GetChildNodes(NodeType.Shape, True).Count > 0 Then
        Console.WriteLine("This table has an image")
    End If
Next

Hope, this helps.

Best regards,