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

Free Support Forum - aspose.com

Extract Group Images

Hi team,


Requiring a Workaround solution for extracting group images with legend from docx.

Also single output document is expected to be generated for a group image like in sample_Output.

Thanking You
Priya Dharshini J P
Hi Priya ,

Thanks for your inquiry. The shared images are not in group shape. These are inside a table. You can extract the desired table using following code example. Hope this helps you.

We suggest you please read following article:
Aspose.Words Document Object Model

Document doc = new Document(MyDir + "figuresV.docx");
Document dstDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(dstDoc);

Table table = (Table)doc.getChild(NodeType.TABLE, 1, true);

NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
Node newNode = importer.importNode(table, true);
dstDoc.getFirstSection().getBody().appendChild(newNode);
dstDoc.getFirstSection().getBody().getFirstParagraph().remove();

dstDoc.save(MyDir + "17.5.0.docx");

Thank you Tahir for the timely help.


I further have a request to filter tables containing only images as in the case of attached sample many other tables not containing images are available. Is there a solution to extract group images from table containing only images.
Also,
getChild(int nodeType, int index, boolean isDeep)


The index variable mentioned here is the index count of all tables in the document. can this variable presumably contain only index of tables containing group images using a filter option.

Thanking You,
Priya Dharshini J P
Hi Priya ,

Thanks for your inquiry. Please use following code example to export the tables that contain the images into new document. Hope this helps you.

int i = 1;
Document doc = new Document(MyDir + "Bernardo_et_al_RevisedPaper (1).docx");

for (Table table : (Iterable
) doc.getChildNodes(NodeType.TABLE, true))
{
Document dstDoc = new Document();
NodeCollection shapes = table.getChildNodes(NodeType.SHAPE, true);
if(shapes.getCount() > 0)
{
for (Shape shape : (Iterable) shapes)
{
if(shape.hasImage())
{
NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
Node newNode = importer.importNode(table, true);
dstDoc.getFirstSection().getBody().appendChild(newNode);
dstDoc.getFirstSection().getBody().getFirstParagraph().remove();

dstDoc.save(MyDir + "document"+ i +".docx");
i++;
break;
}
}
}
}

Thanking You @tahir.manzoor

Regards
Priya Dharshini J P