How to get table tool images?

Dear Team,

I need to extract table tool images from word document using Aspose java. I have attached input for table tool images. Please give solution and example for table tool images.

Input : Fig.zip (2.0 MB)

Regards,
S S Vadivel

@Vadivel_S_S,

Thanks for your inquiry. Your input document contains the embedded OLE. You can use ShapeRenderer.Save method to render the shape and saves into an image. Please check the attached code example.

Document doc = new Document(MyDir + "Fig5.docx");

NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable<Shape>) shapes)
{
    shape.getShapeRenderer().save(MyDir + "output"+i+".png", new ImageSaveOptions(SaveFormat.PNG));
    i++;
}

Could you please ZIP and attach your expected output document? We will then provide you more information on this.

Thanks for your quick replying.
I need to use table object for this scenario. My expected output is Expected_output.zip (1.4 MB).

Extracted output saved as .docx format.(whatever input in word document same as output without figure caption)

Regards,

S S Vadivel

@Vadivel_S_S,

Thanks for sharing the detail. Please use the following code example to get the desired output.

Document doc = new Document(MyDir + "Fig5.docx");

NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph  paragraph : (Iterable<Paragraph>) paragraphs)
{
    if(paragraph.toString(SaveFormat.TEXT).trim().startsWith("Fig"))
    {
        Document dstDoc = new Document();
        Node table = (Table)paragraph.getAncestor(NodeType.TABLE);

        if(table != null)
        {
            paragraph.getAncestor(NodeType.ROW).remove();
            NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
            Node newNode = importer.importNode(table, true);
            dstDoc.getFirstSection().getBody().appendChild(newNode);
            dstDoc.save(MyDir + "output"+i+".docx");
            i++;
        }
    }
}