Thank you for your answer!
Now I am trying to use your example with highlighting for my case.
I have a very simple document:
Your address: [ADDRESS]
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
// This is a Run node that contains either the beginning or the complete match.
Node currentNode = e.MatchNode;
// The first (and may be the only) run can contain text before the match,
// in this case it is necessary to split the run.
if (e.MatchOffset > 0)
currentNode = SplitRun((Run)currentNode, e.MatchOffset);
if (currentNode != null)
DocumentBuilder builder = new DocumentBuilder((Document)currentNode.Document);
builder.InsertTextInput("TextInput", TextFormFieldType.Regular, string.Empty, "MY FIELD", 0);
// This array is used to store all nodes of the match for further highlighting.
ArrayList runs = new ArrayList();
// Find all runs that contain parts of the match string.
int remainingLength = e.Match.Value.Length;
(remainingLength > 0) &&
(currentNode != null) &&
(currentNode.GetText().Length <= remainingLength))
remainingLength = remainingLength - currentNode.GetText().Length;
// Select the next Run node.
// Have to loop because there could be other nodes such as BookmarkStart etc.
currentNode = currentNode.NextSibling;
while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));
// Split the last run that contains the match if there is any text left.
if ((currentNode != null) && (remainingLength > 0))
// Removes all matched runs
foreach (Run run in runs)
Your address: MY FIELD
YouMY FIELD name: [NAME]
As you see the first loop works well. I get MY FIELD at the right place. But second one comes to the wrong place. As I understand it happens because the document was changed after the first loop and that is why the second field is not placed correctly.
Can you help me with this?
And an additional question: How to change background color of text input field?