Free Support Forum -

Extract all the images

Hi Team,

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


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.

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


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. (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")) {
        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);
   + "output"+i+".docx");