@priyadharshini,
Thanks for your inquiry. Please use the following code example to extract the desired contents from the document. Hope this helps you.
Document doc = new Document(MyDir + "Source_2.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
int bookmark = 1;
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 PreviousPara = paragraph.getPreviousSibling();
while (PreviousPara != null
&& PreviousPara.getNodeType() == NodeType.PARAGRAPH
&& (
PreviousPara.toString(SaveFormat.TEXT).trim().length() == 0 ||
PreviousPara.toString(SaveFormat.TEXT).trim().contains("(a)") ||
PreviousPara.toString(SaveFormat.TEXT).trim().contains("(b)") ||
PreviousPara.toString(SaveFormat.TEXT).trim().contains("(c)") ||
PreviousPara.toString(SaveFormat.TEXT).trim().contains("(d)"))
)
{
PreviousPara = PreviousPara.getPreviousSibling();
}
if(PreviousPara == null)
{
builder.moveToDocumentStart();
builder.startBookmark("Bookmark" + bookmark);
}
else
{
builder.moveToParagraph(paragraphs.indexOf((Paragraph)PreviousPara), -1);
builder.startBookmark("Bookmark" + bookmark);
}
builder.moveToParagraph(paragraphs.indexOf(paragraph), 0);
builder.endBookmark("Bookmark" + bookmark);
bookmark++;
}
}
for (Bookmark bm : doc.getRange().getBookmarks())
{
if(bm.getName().startsWith("Bookmark"))
{
ArrayList nodes = ExtractContents.extractContent(bm.getBookmarkStart(), bm.getBookmarkEnd(), true);
Document dstDoc = ExtractContents.generateDocument(doc, nodes);
dstDoc.save(MyDir + "output"+i+".docx");
i++;
}
}