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

RadDocument HTML Export, CSS-class names

1 Answer 68 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Li
Top achievements
Rank 1
Li asked on 04 Sep 2012, 07:59 AM
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>
<br>
StyleDefinition style = ...;<br>
style.Name = "MyStyleNameWhichIWantToSeeUsedInTheHtmlExport_AndNot_ARandomizedNumber");<br>
style.DisplayName = style.Name;<br>
<br>
document.StyleRepository.Add(style);<br>
<br>
RadDocument fragmentDocument = new RadDocument();<br>
Section section = new Section();<br>
Paragraph paragraph = new Paragraph();<br>
<br>
MergeField field = new MergeField();<br>
<br>
String propertyPath = "FunnyPropertyPath";<br>
<br>
field.PropertyPath = propertyPath;<br>
Span span = new Span("{MERGEFIELD " + propertyPath + "}");<br>
span.StyleName = style.Name;<br>
<br>
FieldRangeStart start = new FieldRangeStart();<br>
FieldRangeEnd end = new FieldRangeEnd();<br>
start.End = end;<br>
start.Field = field;<br>
<br>
paragraph.Inlines.Add(start);<br>
paragraph.Inlines.Add(span);<br>
<br>
paragraph.Inlines.Add(end);<br>
<br>
section.Blocks.Add(paragraph);<br>
fragmentDocument.Sections.Add(section);<br>
<br>
fragmentDocument.MeasureAndArrangeInDefaultSize();<br>
fragmentDocument.Selection.SelectAll();<br>
DocumentFragment fragment = fragmentDocument.Selection.CopySelectedDocumentElements();<br>
<br>
document.InsertFragment(fragment);<br>
<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>
<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>
<head><br>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br>
<title>Untitled</title><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>
}<br>
<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>
}<br>
</style><br>
</head><br>
<body><br>
    <p class="<b>p_CC664AAA</b>"><br>
        <span class="<b>s_E6FD2046</b>">test { MERGEFIELD FunnyPropertyPath}Text</span><br>
    </p><br>
</body><br>
</html><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.

1 Answer, 1 is accepted

Sort by
0
Alex
Telerik team
answered on 06 Sep 2012, 02:25 PM
Hi,

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,
Alex
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Li
Top achievements
Rank 1
Answers by
Alex
Telerik team
Share this question
or