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

Html Export failure

1 Answer 66 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rahil Kidwai
Top achievements
Rank 1
Rahil Kidwai asked on 10 Jul 2012, 04:26 PM
I am trying to load html in RichTextBox control using HtmlDataProvider. The html contain style definitions defined within <Style> tag.
The RichTextBox fails to load the html with embedded <Style> tag. 

Here is a sample html I am trying to load.

<!DOCTYPE><HTML><STYLE>P {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0in;text-indent:0.25in;font-weight:normal}P.freetext {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0in;text-indent:0in;font-weight:normal}P.outline {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0;text-indent:0in;font-weight:normal}P.outline1 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0;text-indent:0in;font-weight:normal}P.outline2 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0;text-indent:0in;font-weight:normal}P.outline3 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0;text-indent:0in;font-weight:normal}H1 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0in;text-indent:0in;font-weight:normal}H2 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0in;text-indent:0in;font-weight:normal}H3 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0in;text-indent:0in;font-weight:normal}H4 {margin-bottom:0in;margin-right:0in;margin-top:0in;margin-left:0in;text-indent:0in;font-weight:normal}UL {margin-top:0in;margin-bottom:0in;font-weight:normal}OL {margin-top:0in;margin-bottom:0in;font-weight:normal}A.a0:link {color: #000000; }A.a0:visited {color: #000000; }A.a80:link {color: #FF0000; }A.a80:visited {color: #FF0000; }</STYLE><HEAD><meta http-equiv="Content-Type" Content="text/html;charset=utf-8" ><TITLE></TITLE></HEAD><BODY TOPMARGIN="0" BGCOLOR=#FFFFFF><H1 ID="G20P1"><FONT FACE="Times New Roman" COLOR="#0000FF" SIZE="2"><B>Samle Text</B></FONT></H1><P CLASS=freetext ID="G20P2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2">sample sample sample</FONT>.</FONT></P><H1 ID="G13P1"><FONT FACE="Times New Roman" COLOR="#0000FF" SIZE="2"><B>Plan</B></FONT></H1><P ID="G13P2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2">Sample </FONT></P><UL><LI><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2">sample sample sample</FONT><LI><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2">Sample</FONT></UL><H1 ID="G27P1"><FONT FACE="Times New Roman" COLOR="#0000FF" SIZE="2"><B>Sample</B></FONT></H1><P CLASS=freetext ID="G27P2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2">sample</FONT>.</FONT></P><H1 ID="G62P1"><FONT FACE="Times New Roman" COLOR="#0000FF" SIZE="2"><B>Sample</B></FONT></H1><P CLASS=freetext ID="G62P2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2"><FONT FACE="Times New Roman" COLOR="#000000" SIZE="2">sample sample sample</FONT>.</FONT></P></BODY></HTML>

Here is my code:

<UserControl 
    x:Class="HtmlViewerUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot">
        <telerik:HtmlDataProvider Html="{Binding HtmlContent}" RichTextBox="{Binding ElementName=rtb}">
            <telerik:HtmlDataProvider.FormatProvider>
                <telerik:HtmlFormatProvider>
                    <telerik:HtmlFormatProvider.ExportSettings>
                        <telerik:HtmlExportSettings DocumentExportLevel="Document" StylesExportMode="Inline"/>
                    </telerik:HtmlFormatProvider.ExportSettings>
                </telerik:HtmlFormatProvider>
            </telerik:HtmlDataProvider.FormatProvider>
        </telerik:HtmlDataProvider>

        <telerik:RadRichTextBox 
            x:Name="rtb" 
            IsReadOnly="True" 
            ShowComments="False" 
            IsSelectionMiniToolBarEnabled="False" 
            IsContextMenuEnabled="False" 
            IsImageMiniToolBarEnabled="False" 
            IsSelectionEnabled="False"
            IsSpellCheckingEnabled="False" 
            ShowFormattingSymbols="False" 
            ShowMergeFieldsHighlight="False" 
            AllowScaling="True"
            VerticalAlignment="Stretch" 
            HorizontalAlignment="Stretch"/>
    </Grid>
</UserControl>


Can you tell me how to get it work.
Thanks

1 Answer, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 12 Jul 2012, 04:44 PM
Hi Rahil Kidwai,

HTML is a diverse and complicated standard and supporting it comes with certain limitations. HtmlFormatProvider is designed to handle slightly malformed HTML (missing closing tags, missing quotes around attributes). However your document is not valid XHTML and cannot be parsed and shown correctly. The problems are mainly:

1. Missing closing tags for <LI>

2. Missing quotes in the class declaration 

<P class=freetext ... />

3. Use of capital letters for the declaration of the elements.

For best results we recommend importing valid XHTML content. You can read more about supported html in this article.

Kind regards,
Mihail
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Rahil Kidwai
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Share this question
or