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

Remove Styles from Text

4 Answers 80 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 2
Anthony asked on 08 Nov 2012, 09:05 PM

I'm using the RadRichTextBox to allow users to enter text with spell checking, bold and italics but they can't be allowed to change the font. I've managed to change the context menu to remove font related items, however when I export I found it includes font sizes and families I didn't specify.

I need to do this becuase the text edited will be combined with other edited text fields and shown in a report that has strict styles.

Is it possible to use the HtmlFormatProvider to export the content without specifying the fonts?

Here is what I've tried so far:

 

string buffer;
HtmlExportSettings exportSettings=new HtmlExportSettings();
exportSettings.DocumentExportLevel= DocumentExportLevel.Fragment;
exportSettings.StylesExportMode = StylesExportMode.Classes;
exportSettings.ExportFontStylesAsTags = true;
exportSettings.StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles;
HtmlFormatProvider formatProvider=new HtmlFormatProvider();
formatProvider.ExportSettings=exportSettings;
 
buffer = formatProvider.Export(editor.Document);


Thanks,
Anthony

 

 

 


4 Answers, 1 is accepted

Sort by
0
Accepted
Mihail
Telerik team
answered on 12 Nov 2012, 11:11 AM
Hi Anthony,

You can use export settings to ignore some of the style properties for export. Here is an example how to do it:

exportSettings.PropertiesToIgnore["span"].Add("font-family");

By adding this property to the properties to ignore, you will ensure that it will never be exported.

I hope this fits your requirements.
All the best,
Mihail
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anthony
Top achievements
Rank 2
answered on 13 Nov 2012, 01:13 PM
Thanks Milhail, that worked great!
0
Markus
Top achievements
Rank 2
answered on 14 Nov 2012, 06:45 AM
Hi
How can i do that over the xaml?

Regards Markus
0
Petya
Telerik team
answered on 16 Nov 2012, 08:17 AM
Hi Markus,

I am not quite sure if I understand your question.

If you wish to make the same customization, but use XamlFormatProvider, I am afraid that is not possible, as XamlFormatProvider does not have export settings.

The other thing that comes to mind is that you might be using a data provider and you wish to exclude properties from the exported html. However, this is not possible using XAML because the PropertiesToIgnore dictionary is of type <string, List<string>> and Silverlight does not support generics in XAML.

What you can do is access the format provider used internally by the data provider and achieve the same result as follows:
HtmlExportSettings settings = new HtmlExportSettings();
settings.PropertiesToIgnore["span"].Add("font-family");
HtmlFormatProvider provider = (HtmlFormatProvider)htmlDataProvider.FormatProvider;
provider.ExportSettings = settings;
where htmlDataProvider is the name of your data provider.

I hope this helps! If neither of those fit your case, please get back to us with additional details.

Greetings,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Anthony
Top achievements
Rank 2
Answers by
Mihail
Telerik team
Anthony
Top achievements
Rank 2
Markus
Top achievements
Rank 2
Petya
Telerik team
Share this question
or