This is a migrated thread and some comments may be shown as answers.

MergeField in HTML using style from previous text

0 Answers 95 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Iron
Jakub asked on 03 Jan 2019, 10:07 AM

Hi,

I know importing HTML does not support inserting merge fields automaticaly but in simple loop we can do it in code.

As you can see, we selecting text like {MERGEFIELD NAME} and inserting new merge field. It is working fine, and highlight fields or preview results works correct. The only problem is, when I set some styles in text before merge field, save html and then loads it again, mergefield is going to inherit these styles. This situation is illustrated on screenshots. I set color for second line, then after my InsertMergeFields method inserts all fields, the second line has style from first line, and the third line has styles from second.

It looks like a default behavior from document editors, when caret is placed after red text, next letter will be also red, but can I do something with this?

 

public static void InsertMergeFields(RadDocument radDocument)
       {
           foreach (var mergeField in new DocumentTextSearch(radDocument).FindAll("{MERGEFIELD.*?}"))
           {
               mergeField.SetSelection(radDocument);
               var fieldCode = GetFieldCode(radDocument.Selection.GetSelectedText());
               radDocument.InsertField(new MergeField() { PropertyPath = fieldCode }, FieldDisplayMode.Code);
           }
       }

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Jakub
Top achievements
Rank 1
Iron
Share this question
or