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

Use a MergeField With a Formated (RTF) Text

3 Answers 162 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Emmanuelli
Top achievements
Rank 1
Emmanuelli asked on 04 Jun 2014, 01:43 PM
Hi,

I search to merge a document with some special field formated with Bold and new line in a Document. This "special field" come from a RichTextBox.
Is it possible?

Thx in advance

3 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 09 Jun 2014, 10:19 AM
Hi Emmanuelli,
By default, the data source of the merge fields is merged as plain text (using the current formatting). You can, however, create custom type of merge fields by inheriting MergeField class and overriding GetResultFragment method. This method returns DocumentFragment, which means that you can apply the desired formatting and inlude more than one paragraph (i.e. the new lines). Similar approach is demonstrated in this forum thread. Following is a sample implementation of the GetResultFragment method:
protected override DocumentFragment GetResultFragment()
{
    Person customer = this.Document.MailMergeDataSource.CurrentItem as Person;
 
    if (customer == null)
    {
        return null;
    }
 
    if (this.PropertyPath == "FirstName")
    {
        RadDocumentEditor editor = new RadDocumentEditor(new RadDocument());
 
        editor.Insert(Environment.NewLine);
        editor.Insert(customer.FirstName);
        editor.Insert(Environment.NewLine);
 
        editor.Document.Selection.SelectAll();
        editor.ChangeFontWeight(FontWeights.Bold);
 
        return new DocumentFragment(editor.Document);
    }
 
    return null;
}


You can insert such fields using the RadRichTextBox/RadDocumentEditor's InsertField method:

this.radRichTextBox.InsertField(new CustomMergeField() { PropertyPath = "FirstName" });

Don't hesitate to contact us if you have other questions.


Regards,
Boby
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Emmanuelli
Top achievements
Rank 1
answered on 13 Jun 2014, 01:41 PM
thx for you answer but I search to insert a DocumentFragment coming from an other RadRichTextBox.

I create a DocumentFragment Field with an imported XAML but when I merge with this field, nothing...
0
Boby
Telerik team
answered on 16 Jun 2014, 07:18 AM
Hello Emmanuelli,
Could you explain in more details what is your scenario, as I am having hard time understanding what are you trying to achieve?

Looking forward to your reply.

Regards,
Boby
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RichTextBox
Asked by
Emmanuelli
Top achievements
Rank 1
Answers by
Boby
Telerik team
Emmanuelli
Top achievements
Rank 1
Share this question
or