Problem with RadRichTextBox with HTMLFormatProvider

9 posts, 0 answers
  1. Ran
    Ran avatar
    2 posts
    Member since:
    Dec 2012

    Posted 03 Apr 2013 Link to this post

    Hi,

    I need to display a string which contains HTML as an html page.

    I'm using this xaml:
    <telerik:RadRichTextBox
                x:Name="radRichTextBox"
                IsSpellCheckingEnabled="False" />

    and this code:

    this.radRichTextBox.Document = LoadHtmlFile(sContent);

    public static RadDocument LoadHtmlFile(string content)
            {
                HtmlFormatProvider provider = new HtmlFormatProvider();
                return provider.Import(content);
            }

    the content string contains the following:
    "<HTML>\r\n<HEAD>\r\n<STYLE TYPE=\"text/css\"> \r\n<!-- \r\n.RedText \r\n{ \r\ntext-decoration:underline; \r\ncolor:#0000FF; \r\n} \r\n.BlueText \r\n{ \r\ntext-decoration:line-through; \r\ncolor:#FF0000; \r\n} \r\n--> \r\n</STYLE> \r\n\r\n<TITLE>\r\nTextCompare:: c:\\testdata\\20newstxt\\Atheism\\alt.atheism\\51123.TXT VS c:\\testdata\\20newstxt\\Atheism\\alt.atheism\\51127.TXT\r\n</TITLE>\r\n<script type=\"text/javascript\">\r\n<!--\r\nfunction Loading() { \r\n\tfor (x = 0; x < document.images.length; x++) {\r\n\t\tdocument.images[x].style.display =\"none\"; \r\n\t}\r\n}\r\nfunction CountImg() { \r\n\treturn document.images.length;\r\n}\r\nfunction Next(Sshow,Shide) {\r\n\tvar xx = parseInt(Sshow)-1;\r\n\tvar yy = parseInt(Shide)-1;\r\n\tif ( xx >= 0)\r\n\t\tdocument.images[xx].style.display =\"\";\r\n\tif ( yy >= 0 && !(xx == yy))\r\n\t\tdocument.images[yy].style.display =\"none\"; \r\n}\r\n-->\r\n</script>\r\n\r\n</HEAD>\r\n<BODY onLoad='Loading()'>\r\n\r\n<TABLE>\r\n<TR><TD>Base    </TD><TD><A HREF=\"c:\\testdata\\20newstxt\\Atheism\\alt.atheism\\51123.TXT\">c:\\testdata\\20newstxt\\Atheism\\alt.atheism\\51123.TXT</A></TD></TR>\r\n<TR><TD>Modified</TD><TD><A HREF=\"c:\\testdata\\20newstxt\\Atheism\\alt.atheism\\51127.TXT\">c:\\testdata\\20newstxt\\Atheism\\alt.atheism\\51127.TXT</A></TD></TR>\r\n</TABLE>\r\n\r\n<HR>\r\n\r\n<P>\r\nFrom: keith@cco.caltech.edu (Keith Allan Schneider) \r\n<BR/>\r\nSubject: Re: <IMG src=\"flag1.jpg\" name=\"C211\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">Political Atheists? </SPAN><SPAN CLASS=\"RedText\">&gt;&gt;&gt;&gt;&gt;&gt;Pompous ass </SPAN>\r\n<BR/>\r\nOrganization: California Institute of Technology, Pasadena \r\n<BR/>\r\nLines: <IMG src=\"flag1.jpg\" name=\"C212\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">11 </SPAN><SPAN CLASS=\"RedText\">14 </SPAN>\r\n<BR/>\r\nNNTP-Posting-Host: punisher.caltech.edu <IMG src=\"flag1.jpg\" name=\"C213\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">\r\n<P/>\r\narromdee@jyusenkyou.cs.jhu.edu (Ken Arromdee) </SPAN><SPAN CLASS=\"RedText\">\r\n<P/>\r\nlivesey@solntze.wpd.sgi.com (Jon Livesey) </SPAN>writes: <IMG src=\"flag1.jpg\" name=\"C214\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">\r\n<P/>\r\n&gt;&gt;The motto originated in </SPAN><SPAN CLASS=\"RedText\">\r\n<P/>\r\n&gt;&gt;&gt;How long does it [the motto] have to stay around before it becomes </SPAN>the <IMG src=\"flag1.jpg\" name=\"C215\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">Star-Spangled Banner. Tell me </SPAN><SPAN CLASS=\"RedText\">\r\n<P/>\r\n&gt;&gt;&gt;default? ... Where's the cutoff point? \r\n<P/>\r\n&gt;&gt;I don't know where the exact cutoff is, but it is at least after a few \r\n<P/>\r\n&gt;&gt;years, and surely after 40 years. \r\n<P/>\r\n&gt;Why does the notion of default not take into account changes \r\n<P/>\r\n&gt;in population makeup? \r\n<P/>\r\nSpecifically, which changes are you talking about? Are you arguing </SPAN>that <IMG src=\"flag1.jpg\" name=\"C216\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">this has \r\n<P/>\r\n&gt;&gt;something to do with atheists. \r\n<P/>\r\n&gt;The </SPAN><SPAN CLASS=\"RedText\">the </SPAN>motto <IMG src=\"flag1.jpg\" name=\"C217\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">_on_coins_ originated </SPAN><SPAN CLASS=\"RedText\">is interpreted </SPAN>as <IMG src=\"flag1.jpg\" name=\"C218\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"RedText\">offensive by </SPAN>a <IMG src=\"flag1.jpg\" name=\"C219\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">McCarthyite smear which equated atheism \r\n<P/>\r\n&gt;with Communism and called both unamerican. \r\n<P/>\r\nNo it didn't. The motto has been on various coins since </SPAN><SPAN CLASS=\"RedText\">larger portion of </SPAN>the <IMG src=\"flag1.jpg\" name=\"C220\" alt=\"Flag\"/>\r\n<SPAN CLASS=\"BlueText\">Civil War. \r\n<P/>\r\nIt was just required to be on *all* currency in the 50's. </SPAN><SPAN CLASS=\"RedText\">\r\n<P/>\r\npopulation now than 40 years ago? </SPAN>\r\n<BR/>\r\nkeith \r\n\r\n</P>\r\n\r\n<HR>\r\n\r\n<P>\r\nDocument comparison created by Equivio&gt;Compare, a product of <a href=\"http://www.equivio.com\">Equivio</a>\r\n\r\n</P>\r\n</BODY>\r\n</HTML>"

    The displayed result is a blank page.

    What am I doing wrong here?




  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 03 Apr 2013 Link to this post

    Hello Ran,

    The main problem with the document is that all element names are in capital letters. This is valid HTML, but not XHTML. HtmlFormatProvider expects valid XHTML content, that is why the import sometimes fails when the element names are in capital letters. In the case of your document, it would be enough to substitute all occurrences of "STYLE" with "style".

    Once imported, you can see some differences between the way the document looks in the editor and in a browser. They are mainly due to the fact that most paragraph tags are embedded in span elements, but paragraphs are block elements and spans are inlines, so it must be the other way around.

    I hope this answers your question.

    Regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Ran
    Ran avatar
    2 posts
    Member since:
    Dec 2012

    Posted 04 Apr 2013 Link to this post

    Hi Iva,

    The html is now displayed but most of the colors.
    All tags are now lower case but not all colors are displayed.

    See my two attachments. 
    One is the expected result and one is the actual result.

    Here's the html string:
    <!-- saved from url=(0023)http://www.equivio.com/ -->\r\n<html>\r\n<head>\r\n<style type=\"text/css\"> \r\n<!-- \r\n.RedText \r\n{ \r\ntext-decoration:underline; \r\ncolor:#0000FF; \r\n} \r\n.BlueText \r\n{ \r\ntext-decoration:line-through; \r\ncolor:#FF0000; \r\n} \r\n--> \r\n</style> \r\n\r\n<title>\r\nTextCompare:: c:\\testdata\\20newstxt\\atheism\\alt.atheism\\51124.TXT VS c:\\testdata\\20newstxt\\atheism\\alt.atheism\\51135.TXT\r\n</title>\r\n<script type=\"text/javascript\">\r\n<!--\r\nfunction Loading() { \r\n\tfor (x = 0; x < document.images.length; x++) {\r\n\t\tdocument.images[x].style.display =\"none\"; \r\n\t}\r\n}\r\nfunction CountImg() { \r\n\treturn document.images.length;\r\n}\r\nfunction Next(Sshow,Shide) {\r\n\tvar xx = parseInt(Sshow)-1;\r\n\tvar yy = parseInt(Shide)-1;\r\n\tif ( xx >= 0)\r\n\t\tdocument.images[xx].style.display =\"\";\r\n\tif ( yy >= 0 && !(xx == yy))\r\n\t\tdocument.images[yy].style.display =\"none\"; \r\n}\r\n-->\r\n</script>\r\n\r\n</head>\r\n<body onload='Loading()'>\r\n\r\n<table>\r\n<tr><td>Base    </td><td><a href=\"c:\\testdata\\20newstxt\\atheism\\alt.atheism\\51124.TXT\">c:\\testdata\\20newstxt\\atheism\\alt.atheism\\51124.TXT</a></td></tr>\r\n<tr><td>Modified</td><td><a href=\"c:\\testdata\\20newstxt\\atheism\\alt.atheism\\51135.TXT\">c:\\testdata\\20newstxt\\atheism\\alt.atheism\\51135.TXT</a></td></tr>\r\n</table>\r\n\r\n<hr>\r\n\r\n<p>\r\n<img src=\"flag1.jpg\" name=\"C28\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">From: I3150101@dbstu1.rz.tu-bs.de (Benedikt Rosenau) </span>\r\n<br/>\r\nSubject: Re: <img src=\"flag1.jpg\" name=\"C29\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">An Anecdote about Islam </span><span class=\"RedText\">Ancient islamic rituals \r\n<p/>\r\nFrom: bobbe@vice.ICO.TEK.COM (Robert Beauchaine) </span>\r\n<br/>\r\nOrganization: <img src=\"flag1.jpg\" name=\"C30\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">Technical University Braunschweig, Germany </span><span class=\"RedText\">Tektronix, Inc., Beaverton, OR. </span>\r\n<br/>\r\nLines: <img src=\"flag1.jpg\" name=\"C31\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">28 </span><span class=\"RedText\">33 </span>\r\n<br/>\r\nIn article <img src=\"flag1.jpg\" name=\"C32\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">&lt;114127@bu.edu&gt; \r\n<p/>\r\njaeger@buphy.bu.edu (Gregg Jaeger) </span><span class=\"RedText\">&lt;1993Apr3.081052.11292@monu6.cc.monash.edu.au&gt; darice@yoyo.cc.monash.edu.au (Fred Rice) </span>writes: <img src=\"flag1.jpg\" name=\"C33\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">\r\n<br/>\r\n&gt;&gt;When they are victimized they are Muslims. When they victimize others \r\n<br/>\r\n&gt;&gt;they are not True Muslims (tm) or no Muslims at all. \r\n<br/>\r\n&gt; \r\n<br/>\r\n&gt;&gt;Quite annoying. \r\n<br/>\r\n&gt; </span>\r\n<br/>\r\n&gt;I <img src=\"flag1.jpg\" name=\"C34\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">don't understand the point of this petty sarcasm. It is a basic \r\n<p/>\r\n&gt;principle of Islam that if one is born muslim or one says &quot;I testify </span><span class=\"RedText\">propose </span>\r\n<br/>\r\n&gt;that <img src=\"flag1.jpg\" name=\"C35\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">there is no god but God </span><span class=\"RedText\">these two trends -- greater level of general depression in society \r\n<p/>\r\n&gt;(and other psychological problems) </span>and <img src=\"flag1.jpg\" name=\"C36\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">Mohammad is </span><span class=\"RedText\">greater sexual promiscuity -- are \r\n<p/>\r\n&gt;linked, with the latter being </span>a <img src=\"flag1.jpg\" name=\"C37\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">prophet </span><span class=\"RedText\">prime cause </span>of <img src=\"flag1.jpg\" name=\"C38\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">God&quot; that, \r\n<br/>\r\n&gt;so long as one does not explicitly reject Islam by word then one _must_ \r\n<br/>\r\n&gt;be considered muslim by all muslims. So </span>the <img src=\"flag1.jpg\" name=\"C39\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">phenomenon you're attempting \r\n<p/>\r\n&gt;to make into a general rule or psychology is a direct odds with basic \r\n<p/>\r\n&gt;Islamic principles. If you want </span><span class=\"RedText\">former. I cannot \r\n<p/>\r\n&gt;provide any evidence beyond this at this stage, but the whole thesis \r\n<p/>\r\n&gt;seems very reasonable </span>to <img src=\"flag1.jpg\" name=\"C40\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">attack Islam you could do better than \r\n<p/>\r\n&gt;than to argue against something </span><span class=\"RedText\">me and I request </span>that <img src=\"flag1.jpg\" name=\"C41\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">Islam explicitly contradicts. </span><span class=\"RedText\">people ponder upon it. </span>\r\n<br/>\r\n&gt; <img src=\"flag1.jpg\" name=\"C42\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">\r\n<p/>\r\nIt was no criticism of Islam </span><span class=\"RedText\">\r\n<p/>\r\nDamn right you can't provide any evidence </span>for <img src=\"flag1.jpg\" name=\"C43\" alt=\"Flag\"/>\r\n<span class=\"RedText\">it. \r\n<br/>\r\nRarely are any widespread social phenomenon reducible to such </span>a <img src=\"flag1.jpg\" name=\"C44\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">change, it was </span><span class=\"RedText\">\r\n<p/>\r\nsimple premise. If they were, psychology would be </span>a <img src=\"flag1.jpg\" name=\"C45\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">criticism of </span><span class=\"RedText\">hard science \r\n<p/>\r\nwith roughly </span>the <img src=\"flag1.jpg\" name=\"C46\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">\r\n<p/>\r\narguments used. Namely, whenever people you identify </span><span class=\"RedText\">same mathematical soundness </span>as <img src=\"flag1.jpg\" name=\"C47\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">Muslims are </span><span class=\"RedText\">physics. \r\n<p/>\r\nYour premise may well be right. It is much more likely, however, \r\n<p/>\r\nthat it reflects your socialization and religious background, as \r\n<p/>\r\nwell as your need to validate your religious beliefs. Were I to \r\n<p/>\r\npretend to have all </span>\r\n<br/>\r\nthe <img src=\"flag1.jpg\" name=\"C48\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">victims of </span><span class=\"RedText\">answers (and I don't), I would say that </span>the <img src=\"flag1.jpg\" name=\"C49\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">attacks of others, they are used an argument for \r\n<p/>\r\nthe bad situation of Muslims. But whenever deeds </span><span class=\"RedText\">\r\n<p/>\r\nxenophobia, guilt, and intolerance brought about </span>by <img src=\"flag1.jpg\" name=\"C50\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">Muslim that victimize \r\n<p/>\r\nothers are named, they do not count </span><span class=\"RedText\">adherence to \r\n<p/>\r\nfundamentalist religions play just </span>as <img src=\"flag1.jpg\" name=\"C51\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">an argument because what these \r\n<p/>\r\npeople did was not done as </span><span class=\"RedText\">large </span>a <img src=\"flag1.jpg\" name=\"C52\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">true Muslims. No mention is made how Muslims \r\n<p/>\r\nare </span><span class=\"RedText\">role in depressing </span>the <img src=\"flag1.jpg\" name=\"C53\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">cause </span><span class=\"RedText\">members </span>of <img src=\"flag1.jpg\" name=\"C54\" alt=\"Flag\"/>\r\n<span class=\"BlueText\">a bad situation of another party. \r\n<p/>\r\nDouble standards. \r\n<p/>\r\nBenedikt </span><span class=\"RedText\">our society. \r\n<p/>\r\nYour mileage obviously varies. \r\n<p/>\r\n/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ \r\n<p/>\r\nBob Beauchaine bobbe@vice.ICO.TEK.COM \r\n<p/>\r\nThey said that Queens could stay, they blew the Bronx away, \r\n<p/>\r\nand sank Manhattan out at sea. \r\n<p/>\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ </span>\r\n\r\n</p>\r\n\r\n<hr>\r\n\r\n<p>\r\nDocument comparison created by Equivio&gt;Compare, a product of <a href=\"http://www.equivio.com\">Equivio</a>\r\n\r\n</p>\r\n</body>\r\n</html>

    Please assist.

  5. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 09 Apr 2013 Link to this post

    Hello Ran,

    The problem with your file is that the css classes are placed in a comment. If you remove the comment markers the file should be shown as expected.

    Kind regards,
    Mihail
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Manju
    Manju avatar
    6 posts
    Member since:
    Apr 2014

    Posted 29 Apr 2014 in reply to Iva Toteva Link to this post

    Hi Iva


      Can I use Rad Richtextbox format in MVC ??, I am not finding any article about this, all i find is on Silverlight, which I dont need, I have a Unformatted text from Sql Server, which is

    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
    Transitional//EN\"
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta
    http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"
    /><title>Untitled</title><style
    type=\"text/css\">\r\n.s_D8D99854 { font-family:
    'Verdana';font-style: Normal; }
    \r\n</style></head><body><p ><span
    class=\"s_D8D99854\">&nbsp;hello</span></p></body></html>"

    where all I need is just "Hello" from above values, currently i am able to get this in Controller(action Result), but I am not getting any information to convert it into right format to read(html), Please help in this, I am trying this from 3 days!!

  7. Petya
    Admin
    Petya avatar
    975 posts

    Posted 30 Apr 2014 Link to this post

    Hello,

    This forum concerns RadRichTextBox from the Telerik UI for Silverlight suite. If you want to utilize another tool please address your question to the appropriate forum.

    Overall, integrating a Silverlight control in MVC is possible, here is a blog post that might help you with this task.

    The way RadRichTextBox exports HTML can be modified using the export settings explained here. Due to the difference between the HTML DOM and RadDocument's internal structure it is hard to allow lossless export and keep the HTML simple and clean, so the export options are somewhat limited. If they do not fit your needs I'd suggest post processing the generated document.

    I hope this helps.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  8. Mamtha
    Mamtha avatar
    2 posts
    Member since:
    Jun 2011

    Posted 11 May 2015 Link to this post

    Hi Telerik Team,

      I am using Telerik RadRichTextBox. I am trying to get the text from Clipboard (when user copy pastes onto Telerik RadRichTextBox) and then remove the images if any in the text and then using HtmlFormatProvider -> Import(); method to get the data .

      But this returns a special character at the start of the text. Please see attached text.

    Could you please advice why this is happening and how I can get html text without the special character ??????

    Here is the sample code : 

    string textToInsert = Clipboard.GetText(TextDataFormat.Html);

    //remove the images
    while (true)
    {
    int startIndexOfImage = textToInsert.IndexOf("<img");
    if (startIndexOfImage <= 0)
    {
    break;
    }

    int endIndexOfImage = textToInsert.IndexOf(">", startIndexOfImage);
    textToInsert = textToInsert.Remove(startIndexOfImage, (endIndexOfImage - startIndexOfImage)+1);
    }

    MessageRadRichTextBox.Document = ImportHtmlAsRadDocument(textToInsert);

     

     

    public static RadDocument ImportHtmlAsRadDocument(string content)
    {
    if (content != null)
    {
    HtmlFormatProvider provider = new HtmlFormatProvider();
    return provider.Import(content);
    }
    return new RadDocument();
    }

     

     

  9. Petya
    Admin
    Petya avatar
    975 posts

    Posted 13 May 2015 Link to this post

    Hello Mamtha,

    Could you confirm you are using RadRichTextBox from our Silverlight suite, please?

    The reason I'm asking is the fact that due to a limitation in the Silverlight framework, copying and pasting rich text is not possible and there is no overload of the Clipboard.GetText() method that accepts format.

    In case you are using a control from one of our other suites, please submit the question in the respective forum section.

    Regards,
    Petya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Mamtha
    Mamtha avatar
    2 posts
    Member since:
    Jun 2011

    Posted 14 May 2015 in reply to Petya Link to this post

    Thanks for replying Petya.

    I am newbie and using "RadControls for Winforms" .

    Thanks!

     

Back to Top
DevCraft banner