Images with drawing tool and inside section break

Hi Team,
The requirement is extracting the images and saved into new document.For the extraction process using paragraph node and fig caption as keyword. In my code i have separate the image handling in following ways
Section A-handling figures with caption as previous
Section B-handling images with caption as nextsibling
Section C-handling images inside the table
Section D-handling images landscape mode

The input document having images crated by using drawing tools and also inside the section break.please kindly help me to resolve the same issue.

The source code source.zip (8.3 KB)

The input test.zip (425.2 KB)

The expected output Expected output.zip (573.3 KB)

The actual output actual output.zip (8.2 KB)

Thank you very much,
regards,
pria.

@akshayapria

Thanks for your inquiry. As suggested in earlier post, you have to bookmark the contents to extract the images with desired text from different sections and later generate a word document accordingly. Please check following documentation link, it will help you to accomplish the task.

Extract selected contents between nodes

Hi @tilal.ahmad,

I have tried to remove the section break and then try to extract the same .it will not working .
please kindly help me to solve the issue.

Thanks & regards ,
pria

@akshayapria

As suggested above, you need to use bookmarks to group the nodes and extract contents between these bookmarks. If you are facing some issue in this approach, then please share the related code here. We will look into it and will guide you accordingly.

Hi @tilal.ahmad ,

Thank you very much.

please,share some samples code to bookmark to group the nodes and extract the contents.

Thanks & regards
pria

@akshayapria

Thanks for your feedback. We have already shared couple of times sample code with you. Please check following code snippet to bookmark some contents and extract them later. You need to customize it as per your need. Please find code of referenced methods from following documentation link.

Extract selected contents between nodes

com.aspose.words.Document doc = new com.aspose.words.Document("test.docx");
DocumentBuilder builder = new DocumentBuilder(doc);


for (Paragraph  paragraph : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {

    if(paragraph.toString(com.aspose.words.SaveFormat.TEXT).trim().contains("Start text"))
    {
        builder.moveTo(paragraph);
        builder.startBookmark("Bookmark1");
        builder.endBookmark("Bookmark1");
    }
    if(paragraph.toString(com.aspose.words.SaveFormat.TEXT).trim().startsWith("Figure7"))
    {
        builder.moveTo(paragraph);
        builder.startBookmark("Bookmark2");
        builder.endBookmark("Bookmark2");
        break;
    }
}

Node start = doc.getRange().getBookmarks().get("Bookmark1").getBookmarkStart().getParentNode();
Node end = doc.getRange().getBookmarks().get("Bookmark2").getBookmarkStart().getParentNode();
ArrayList nodes = extractContent(start, end, true);

com.aspose.words.Document dstDoc = generateDocument(doc, nodes);
dstDoc.getLastSection().getBody().getLastParagraph().remove();
dstDoc.save("output.docx");