RadDocument HTML Export, CSS-class names

2 posts, 0 answers
  1. Li
    Li avatar
    46 posts
    Member since:
    Feb 2011

    Posted 04 Sep 2012 Link to this post

    I want to export a RadDocument with a HtmlFormatProvider. But my registered StyleDefinitions (which have a dedicated Name and DisplayName Property) "loose" their name in the export and replaced by something "random".

    RadDocument document = RadRichTextBox.Document;<br>
    StyleDefinition style = ...;<br>
    style.Name = "MyStyleNameWhichIWantToSeeUsedInTheHtmlExport_AndNot_ARandomizedNumber");<br>
    style.DisplayName = style.Name;<br>
    RadDocument fragmentDocument = new RadDocument();<br>
    Section section = new Section();<br>
    Paragraph paragraph = new Paragraph();<br>
    MergeField field = new MergeField();<br>
    String propertyPath = "FunnyPropertyPath";<br>
    field.PropertyPath = propertyPath;<br>
    Span span = new Span("{MERGEFIELD " + propertyPath + "}");<br>
    span.StyleName = style.Name;<br>
    FieldRangeStart start = new FieldRangeStart();<br>
    FieldRangeEnd end = new FieldRangeEnd();<br>
    start.End = end;<br>
    start.Field = field;<br>
    DocumentFragment fragment = fragmentDocument.Selection.CopySelectedDocumentElements();<br>
    HtmlFormatProvider htmlFormatProvider = new HtmlFormatProvider();<br>
    htmlFormatProvider.ExportSettings = new HtmlExportSettings();<br>
    htmlFormatProvider.ExportSettings.StylesExportMode = StylesExportMode.Classes;<br>
    htmlFormatProvider.ExportSettings.ImageExportMode = ImageExportMode.Base64Encoded;<br>
    htmlFormatProvider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Document;<br>
    String htmlExportWithCssNamesWhichSeemToBeGeneratedWithSomeKindOfHash = htmlFormatProvider.Export(document);

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br>
    <html xmlns="http://www.w3.org/1999/xhtml"><br>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br>
    <style type="text/css"><br>
      .<b>p_CC664AAA</b> {<br>
        margin: 0px 0px 12px 0px;<br>
        text-align: left;<br>
        text-indent: 0pt;<br>
        padding: 0px 0px 0px 0px;<br>
    .<b>s_E6FD204</b>6 {<br>
        font-family: 'Verdana';<br>
        font-style: Normal;<br>
        font-weight: normal;<br>
        font-size: 16px;<br>
        color: #000000;<br>
        <p class="<b>p_CC664AAA</b>"><br>
            <span class="<b>s_E6FD2046</b>">test { MERGEFIELD FunnyPropertyPath}Text</span><br>

    How can I change this behavior?

    The reason is that we want to send the HTML to another system were the CSS-Names inherently contain processing information and we have to change (some, not all) generated CSS names to our requirement.
  2. Alex
    Alex avatar
    130 posts

    Posted 06 Sep 2012 Link to this post


    To enable exporting styles from the document's StyleRepository to actual CSS classes you need to set the StyleRepositoryExportMode property of the ExportSettings to StyleRepositoryExportMode.ExportStylesAsCssClasses. 

    I hope this was helpful.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top