Hi,
I am using Aspose.Words to dynamically add StructuredDocumentTag(std). I am able to add it successfully but it does not carry the font and other style of the containing paragraph.
I have attached sample code, Input dotx and output dotx.
Thanks
VinayCode-Input-Output.zip (37.7 KB)
@szawaideh,
You can workaround this problem by using the following code in “IReplacingCallback.Replacing” method:
// Split the last run that contains the match if there is any text left.
if ((currentNode != null) && (remainingLength > 0))
{
SplitRun((Run)currentNode, remainingLength);
runs.Add(currentNode);
}
Run run = (Run)runs[0];
var doc = (Document)e.MatchNode.Document;
builder.MoveTo(run);
Run cloned = (Run)run.Clone(true);
cloned.Text = "replaced";
StructuredDocumentTag sdtForPatientName = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
sdtForPatientName.RemoveAllChildren();
sdtForPatientName.AppendChild(cloned);
sdtForPatientName.Title = "username";
sdtForPatientName.Tag = "username";
sdtForPatientName.IsShowingPlaceholderText = false;
builder.InsertNode(sdtForPatientName);
foreach (Run node in runs)
{
node.Remove();
}
return ReplaceAction.Skip;
}