RichTextBox: export in html and txt

4 posts, 0 answers
  1. Antonio Roman
    Antonio Roman avatar
    3 posts
    Member since:
    May 2010

    Posted 06 Sep 2010 Link to this post

    Hi,

    I'm making a Word application, and I need export a text in string when the user enter text in the RichTextBox, in html and txt, when the user save this document. 
    I've been looking at different posts of the forum, and I don't get a string with the plain text format. I'm using -Telerik.Windows.Documents.FormatProviders.Txt-, as I have seen in other post (http://www.telerik.com/community/forums/silverlight/richtextbox/how-to-validate-there-is-no-text-in-richtextbox.aspx):

    ITextBasedDocumentFormatProvider exporter = new TxtFormatProvider();
    string text = exporter.Export (document);


    But if this is correct, I can't recognize me ITextBasedDocumentFormatProvider interface, and therefore not get the plain text. I'm doing something wrong or I need some assembly?

    On the other hand, to export the text in html conducted the following method:
    public string ExportToHtml(RadDocument document)
    {
        IDocumentFormatProvider provider = new HtmlFormatProvider();
        string exportValue = String.Empty;
        using (MemoryStream output = new MemoryStream())
        {
            provider.Export(document, output);
            output.Seek(0, SeekOrigin.Begin);
            using (StreamReader reader = new StreamReader(output))
            {
                exportValue = reader.ReadToEnd();
            }
        }
        return exportValue;
    }

    Is it right?

    Thank you for your attention.

  2. Boby
    Admin
    Boby avatar
    685 posts

    Posted 09 Sep 2010 Link to this post

    Hello Antonio Roman,
    Exporting RadDocument to HTML string could be done with the following sample code(you will need a reference to the Telerik.Windows.Documents.FormatProviders.Html.dll assembly where the HtmlFormatProvider is located):
    string text = new HtmlFormatProvider().Export(richTextBox.Document);

    and here is how to export the document as plain text (you don't need additional references for this one because the TxtFormatProvider is located in the same assembly as RadDocument - Telerik.Windows.Documents.dll):
    string text = new TxtFormatProvider().Export(richTextBox.Document);

    Please post back if you have any other questions.

    Kind regards,
    Boby
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. Kamasani
    Kamasani avatar
    3 posts
    Member since:
    Oct 2011

    Posted 28 Oct 2011 Link to this post

    Hi When i am exporting to html it is exporting with class names can you please let me know can i export to html with out the class names
    It shoud contain the actual html colours or styles.
    Please find the sample below

    <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.p_384D933F { margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; } \r\n.s_3E433E59 { font-family: 'Verdana';font-style: Italic;font-weight: bold;font-size: 16px;color: #00B050;text-decoration: underline; } \r\n.s_E6FD2046 { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; } \r\n</style></head><body><p class=\"p_384D933F\"><span class=\"s_3E433E59\">PAPI REDDY KAMASANI</span><span class=\"s_E6FD2046\" /></p></body></html>

  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 01 Nov 2011 Link to this post

    Hi Kamasani,

    The styles can be exported as Classes and Inline, the default value being "Classes". This customization option is available through the export settings of HtmlFormatProvider. Please refer to this article for more information on how this can be done.

    Greetings,
    Iva Toteva
    the Telerik team

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

Back to Top