Hi,
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.
@Gptrnt
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);
builder.moveTo(newRun);
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!!!.
@Gptrnt
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.