Splitting document based on start and end text

Hi Tahir,
Thanks for your explanation. I understood now why it’s not able to find the text using aspose.
I will share a little background about our application. We have a content analyzer engine and we provide the content of the whole document as input to it. The engine will logically divide the document based on the content and provide us the start and end boundaries of each logical section in plain text. We plan to use ASPOSE api to physically divide the parent document into small child documents, by adding bookmarks on boundaries and extract content between the bookmarks.
The boundaries provided by the engine are plain text and we do not know any phrase is having hyperlink in it or not. If we know the words contains hyperlinks, we can use regex to exclude that part while matching. So, we are facing difficulties when the boundaries contains hyperlinks. There maybe cases that a boundary may contain multiple hyperlinks in it.
I would like to know if there is any way in ASPOSE to find text as its appearing of the screen. For e.g., in the attached document above, the text displaying in word as “Distribute securities as part of securities underwriting” but in actual it is "Distribute securities as part of { HYPERLINK "http://fs.wiki.goto-psi.com/SecuritiesUnderwriting" }. Is there a way to find the text by just providing “Distribute securities as part of securities underwriting” as the search string – as we can do it in the word editor?
Appreciate your quick reply. Thanks.

Hi Renjith,

Thanks for your inquiry. In your case, we suggest you please iterate through the paragraphs of document and check if paragraph’s text contains the endText. If yes, insert the bookmark at the start/end of paragraph according to your requirements. Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "09_Securities+Trading+Regulations.docx");
doc.getRange().replace(ControlChar.NON_BREAKING_SPACE, " ", new FindReplaceOptions());
String text= "Distribute securities as part of securities underwriting";
for (Paragraph paragraph : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
    if(paragraph.toString(SaveFormat.TEXT).trim().contains(text))
    {
        BookmarkStart bs = new BookmarkStart(doc, "bookmark");
        BookmarkEnd be = new BookmarkEnd(doc, "bookmark");
        Run run = paragraph.getRuns().get(paragraph.getRuns().getCount() - 1);
        run.getParentParagraph().insertAfter(bs, run);
        bs.getParentNode().insertAfter(be, bs);
        break;
    }
}

A post was split to a new topic: The process freezes when call doc.ProcessParagraph()