Remove Styles from Text

5 posts, 1 answers
  1. Anthony
    Anthony avatar
    10 posts
    Member since:
    Feb 2009

    Posted 08 Nov 2012 Link to this post

    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

     

     

     


  2. Answer
    Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 12 Nov 2012 Link to this post

    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.

  3. DevCraft banner
  4. Anthony
    Anthony avatar
    10 posts
    Member since:
    Feb 2009

    Posted 13 Nov 2012 Link to this post

    Thanks Milhail, that worked great!
  5. Markus Wenzel
    Markus Wenzel avatar
    20 posts
    Member since:
    Dec 2009

    Posted 14 Nov 2012 Link to this post

    Hi
    How can i do that over the xaml?

    Regards Markus
  6. Petya
    Admin
    Petya avatar
    975 posts

    Posted 16 Nov 2012 Link to this post

    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.

Back to Top
DevCraft banner