We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to bookmark the content and extract them using Java


I am finding a hidden token and replace it with a bookmark. And extracting the content between the bookmark. After that content converts to another document. But while replacing the token word last “|” hidden character is still showing in the extracted document. Please tell me if I am doing anything wrong.
wrdHtmlWithReplacePoc.zip (69.3 KB)

My Source code, input, output, and the expected output files are uploaded with the zip. Please look in to it.


In your code, you are inserting BookmarkStart node before “|”. Please use the following modified code snippet to get the desired output.

public int replacing(ReplacingArgs e) throws Exception {
    DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
        else if (text.startsWith("|")) {
            Run tempRun = (Run) runs.get(runs.size()-1);
            Run newRun = new Run((Document) e.getMatchNode().getDocument());
            tempRun.getParentParagraph().insertAfter(newRun, tempRun);

            if (text.toLowerCase().contains("p")) {
                builder.startBookmark(Constants.PREAMBLE + sNo);
            }else if (text.toLowerCase().contains("r")) {
                builder.startBookmark(Constants.RESOLUTION + sNo);
    return ReplaceAction.SKIP;

Thank you so much. It’s working great!!!.


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.