Extract all the images

Hi Team,

I have a input document Bernardo_et_al_RevisedPaper_shape.zip (3.8 MB)
from which I have to get all the numbered images extracted as Bernardo_et_al_RevisedPaper-shapes.zip (3.9 MB) and the interim with bookmark generated is Bernardo_et_al_RevisedPaper_Interim.zip (44.4 KB) Here Fig 9,10,13 are table images where I am unable to place the bookmark. Kindly help please.

@Saranya_Sekar

Thanks for your inquiry. In this case, there is no need to bookmark the table’s content. Please import the table into new document. We already shared the code examples to import the node into new document in your other threads. Please use Node.GetAncestor method to check if Shape node (image) has parent node as table.

@tahir.manzoor
Can I get the complete code sample.I am unable to extract all the images .Kindly help please.

@Saranya_Sekar

Thanks for your inquiry. Please use the following code example to get the desired output. We have attached the output documents with this post for your kind reference. Docs.zip (644.5 KB)

Document doc = new Document(MyDir + "Bernardo_et_al_RevisedPaper_shape.docx");
int i = 1;
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph  paragraph : (Iterable<Paragraph>) paragraphs) {
    if (paragraph.toString(SaveFormat.TEXT).trim().startsWith("Fig")) {
        System.out.println(paragraph.getText());
        Node PreviousNode = paragraph.getPreviousSibling();
        if (PreviousNode != null && PreviousNode.getNodeType() == NodeType.TABLE &&
                ((Table) PreviousNode).getChildNodes(NodeType.SHAPE, true).getCount() > 0)

        {
            Document dstDoc = new Document();
            NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
            Node newNode = importer.importNode(PreviousNode, true);
            dstDoc.getFirstSection().getBody().appendChild(newNode);
            dstDoc.save(MyDir + "output"+i+".docx");
            i++;
        }
    }
}